A VB Scrolling Form

With MFC you can use a CFormView that scrolls to show a "virtual" form that might be larger than the window. VB doesn't have an easy way to do this... or does it?

You can accomplish this by using a borderless frame to contain the components in the form (except for the scroll bar). Here's an example of how to do it. The program creates 500 labels and uses a scroll bar to move between them. The program contains a scroll bar and a frame. The frame contains a label in a control array and dynamically creates the other 499 labels at run time.

Here's the code:

Private Sub Form_Load()
' Set frame's height to the "virtual screen size (500 items)"
Frame1.Height = Label1(0).Height * 500
' Set scroll bar parameters (0-499)
VScroll1.Max = 499
VScroll1.Min = 0
' Create (or place) the 500 items -- labels in this case
For i = 1 To 499
  Load Label1(i)
  Label1(i).Top = Label1(0).Height * i
  Label1(i).Caption = i
  Label1(i).Visible = True
Next
End Sub

Private Sub Form_Resize()
Frame1.Width = ScaleWidth - VScroll1.Width
VScroll1.Left = Frame1.Width
VScroll1.Height = ScaleHeight
End Sub

Private Sub VScroll1_Change()
  ' Calculate the new top of the frame as a negative number
  Frame1.Top = -Label1(0).Height * VScroll1.Value
End Sub