Create a Scrollable VB Form
I have been asked a million times: "How do I create a form I can scroll?"
Well here it is. All you need is a scrollbar control and a few lines of
code. For a sample of creating a scrollable form and adding controls to is at
runtime, see my Dynamically Add Controls sample.
Download Source Code
Create a form with a scrollbar on it.
Copy the following code to the Declarations section of a Form:
Dim oldPos As Integer
Copy the following code to the Form Load event:
Private Sub Form_Load()
Dim iFullFormHeigth As Integer
Dim iDisplayHeight As Integer
iFullFormHeigth = 3765
iDisplayHeight = 1800
Me.Height = iDisplayHeight
.Height = Me.ScaleHeight
.Min = 0
.Max = iFullFormHeigth - iDisplayHeight
.SmallChange = Screen.TwipsPerPixelY * 10
.LargeChange = .SmallChange
Create this procedure:
Private Sub pScrollForm()
Dim ctl As Control
For Each ctl In Me.Controls
If Not (TypeOf ctl Is VScrollBar) And _
Not (TypeOf ctl Is CommandButton) Then
ctl.Top = ctl.Top + oldPos - VScroll1.Value
oldPos = VScroll1.Value
Call it from these events:
Private Sub VScroll1_Change()
Private Sub VScroll1_Scroll()
Download this project and run it. Click away on the scroll bar.