Reputation: 6783
My Windows Application in VB 6 is having a form that contains hell lot of controls. And if the screen size at client's environment is smaller, most of the controls do not appear. What I want to do is to provide users a vertical and horizontal scrollbar so that user can scroll across all controls. Anyone having any idea of how to implement this?
P.S. Please do not provide examples showing just labels to display scroll value :)
Upvotes: 2
Views: 29169
Reputation: 9726
I like David's answer, but if you want to do this with the scrollbars, first, you need to put all of your controls into a frame that fits them. You want to move 1 control not a "hell of a lot of controls". Second put your scroll bars into the form and in the Form_Resize event add some code to resize the scroll bars with the form. After resizing the scrollbar you need to do some math to set the Max, SmallChange, and LargeChange properties. I am showing the Min property just so you know it never changes, just set it in the designer. This example uses only a horizontal scrollbar because I am too lazy to include a vertical scrollbar too. Finally, add code to the scrollbar Change event to move the frame around.
Private Sub Form_Resize()
HScroll1.Move 0, Me.ScaleHeight - HScroll1.Height, Me.ScaleWidth
HScroll1.Min = 0
HScroll1.Max = Frame1.Width - Me.ScaleWidth
HScroll1.SmallChange = HScroll1.Max / 100
HScroll1.LargeChange = HScroll1.Max / 10
End Sub
Private Sub HScroll1_Change()
Frame1.Left = -HScroll1.Value
DoEvents ' this is not strictly necessary, but smooths the scolling some
End Sub
You also need error handling code. I am a lazy example coder.
Upvotes: 4
Reputation: 2970
One way is to turn on the scroll bars of your form using Windows API calls. This is different from using ScrollBar controls; turning on the form's own scroll bars keeps the scroll bars from interfering with the tab order, for example.
Here is a good page explaining how to do this, along with a helper class:
Upvotes: 4