Click to See Complete Forum and Search --> : Scroll a form
cedx
Jan 26th, 2000, 10:51 AM
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.
MartinLiss
Jan 27th, 2000, 12:17 AM
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). 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.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.