This is one of the simplest, but most powerful, ways to make a form scrollable. This method automatically disables or enables scrollbars according to the size of the area in relation to the form.
- Add a Picturebox
- Add a VScrollBar
- Add a HScrollBar
- Add the following code to the form:
Private Sub Form_Resize()
VScroll1.Move ScaleWidth - VScroll1.Width, ScaleTop, VScroll1.Width, ScaleHeight - HScroll1.Height
HScroll1.Move ScaleLeft, ScaleHeight - HScroll1.Height, ScaleWidth - VScroll1.Width, HScroll1.Height
Scrolling
End Sub
Private Sub Scrolling()
If Picture1.Width > (ScaleWidth - VScroll1.Width) Then
HScroll1.Max = Picture1.Width - (ScaleWidth - VScroll1.Width)
HScroll1.Enabled = True
Else
HScroll1.Max = HScroll1.Min
HScroll1.Enabled = False
End If
If Picture1.Height > (ScaleHeight - HScroll1.Height) Then
VScroll1.Max = Picture1.Height - (ScaleHeight - VScroll1.Height)
VScroll1.Enabled = True
Else
VScroll1.Max = VScroll1.Min
VScroll1.Enabled = False
End If
Picture1.Move -HScroll1.Value, -VScroll1.Value
End Sub
Private Sub HScroll1_Change()
Scrolling
End Sub
Private Sub VScroll1_Change()
Scrolling
End Sub