Results 1 to 2 of 2

Thread: Scroll a form

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 1999
    Posts
    80

    Post

    Hi,

    I have a MDI child form that is larger than it's parent form. To compensate, VB added a vertical scroll bar to it.

    My problem now is, how do I avoid using the mouse to move the scroll bar and use the keyboard instead (PgUp and PgDown)?

    If I detect the page up and down keys, what do I have to move?

    Thanks in advance.

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    Here is a routine that you can put in your MDI Child's Form_KeyDown event (assuming the child's KeyPreview property is set to True).
    Code:
        Dim nOnePage As Integer
        
        nOnePage = 500
        
        Select Case KeyCode
            Case vbKeyPageDown
                If Form1.Top - nOnePage <= MDIForm1.ScaleHeight - Form1.Height Then
                    Form1.Top = -(Form1.Height - MDIForm1.ScaleHeight)
                Else
                    Form1.Top = Form1.Top + -nOnePage
                End If
            Case vbKeyPageUp
                If Form1.Top + nOnePage >= 0 Then
                    Form1.Top = 0
                Else
                    Form1.Top = Form1.Top + nOnePage
                End If
        End Select
    Change the size of nOnePage to however much you want to scroll the form on one key press. The problem with this routine is that it does not affect the scroll bar that VB added to the child form. If you know how to do that, please E-mail me.

    Rather than scrolling the whole form, here is a different approach. Adjust the child form's height so that it just fits its parent's window. Then on the child form add a picture control, place another picture control inside that one and then place all controls inside that second picture and add a scrollbar on the child form. You can then scroll the picture up and down via the scrollbar (or PageUp and PageDown). If you are interested in this second approach, let me know and I'll send you a demo project.

    ------------------
    Marty
    COGITO EGGO SUM
    I think; therefore I am a waffle.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width