visual basic scroll bar question

truc0011
truc0011 used Ask the Experts™
on
How do I add a scroll bar to a form?  To just scroll up and down the form in case of data not being displayed on the screen?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
The best thing you can do is draw in your form some kind of container (a flat picture box would do) and the draw all your controls as part of the container.

Add a vertical scroll bar (VScrollBar).

In the change event of the vertical scroll bar you can retrieve the value property of the scroll bar itself and change the top property of the picture box (moving the control and all the objects with it).

You're also gonna need to write some code in the form_resize event to keep the scroll bar to the right of the form with the same heigth of form.scaleheigth.
Commented:
I think this is what you're looking for.  You may want to adjust your LargeChange and SmallChange properties on the Scrollbar.

Just add a Vertical scrollbar to your form for this code to work.  You may need to adjust the default name of the scrollbar "VScroll1" to whatever the name is of your vertical scrollbar, and also the default name of "Form1" to the name of your form.


Option Explicit
Private OldValue As Long

Private Sub VScroll1_Change()
Dim Ctrl As Control

For Each Ctrl In Form1.Controls
   If Ctrl.Name <> "VScroll1" Then 'move everything except VScroll1
       If VScroll1.Value > OldValue Then
           Ctrl.Move Ctrl.Left, Ctrl.Top - (VScroll1.Value - OldValue)
       Else
           Ctrl.Move Ctrl.Left, Ctrl.Top + (OldValue - VScroll1.Value)
       End If
   End If
Next Ctrl
OldValue = VScroll1.Value

End Sub

Author

Commented:
Great help!
Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial