HOWTO: Scroll a Form When VB Forms Are Limited to Screen SizeID: Q109741
|
A Visual Basic form cannot be sized larger than the screen. This article
explains how to scroll the contents of a form to enlarge the usable area of
a form.
The sample program below works by scrolling a picture box control which is
larger than the form and contains attached controls. When the picture box
scrolls, all the attached controls scroll together.
Sub Form_Load ()
' Make the picture box bigger than the form:
Picture1.Move 0, 0, 1.4 * ScaleWidth, 1.2 * ScaleHeight ' Place
some sample controls in the picture box:
Dim i As Integer
For i = 1 To 20
Load Text1(i)
Text1(i).Visible = True
Text1(i).Left = i * Picture1.Height / 20
Text1(i).Top = Text1(i).Left
Next
End Sub
Sub Form_Resize ()
' Position the scroll bars:
hscroll1.Left = 0
vscroll1.Top = 0
If Picture1.Width > scalewidth Then
hscroll1.Top = ScaleHeight - hscroll1.Height
Else
hscroll1.Top = ScaleHeight
End If
If Picture1.Height > hscroll1.Top Then
vscroll1.Left = scalewidth - vscroll1.Width
If Picture1.Width > vscroll1.Left Then
hscroll1.Top = ScaleHeight - hscroll1.Height
End If
Else
vscroll1.Left = scalewidth
End If
hscroll1.Width = scalewidth
If hscroll1.Top > 0 then vscroll1.Height=hscroll1.Top
' Set the scroll bar ranges
hscroll1.Max = Picture1.Width - vscroll1.Left
vscroll1.Max = Picture1.Height - hscroll1.Top
hscroll1.SmallChange = Abs(hscroll1.Max \ 16) + 1
hscroll1.LargeChange = Abs(hscroll1.Max \ 4) + 1
vscroll1.SmallChange = Abs(vscroll1.Max \ 16) + 1
vscroll1.LargeChange = Abs(vscroll1.Max \ 4) + 1
hscroll1.ZOrder 0
vscroll1.ZOrder 0
End Sub
Sub HScroll1_Change ()
Picture1.Left = -HScroll1.Value
End Sub
Sub VScroll1_Change ()
Picture1.Top = -VScroll1.Value
End Sub
Additional query words: 3.00 4.00 vb416
Keywords : kb16bitonly kbVBp300 kbVBp400 PrgOther
Version : WINDOWS:3.0,4.0
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: July 20, 1999