You are on page 1of 11

ScrollBar Control

• The ScrollBar controls display vertical and


horizontal scroll bars on the form. This is used
for navigating through large amount of
information.
• There are two types of scroll bar controls:
HScrollBar for horizontal scroll bars and
VScrollBar for vertical scroll bars.
• These are used independently from each other.
ScrollBar Control continue
• The scroll bar is a commonly used control
which enables a user to select a value by
positioning it at the desired location.
• It represents a set of values.

Properties of the ScrollBar Control
• AutoSize: Gets or sets a value indicating whether the ScrollBar is automatically resized to fit
its contents.
• BackColor: Gets or sets the background color for the control.

• ForeColor: Gets or sets the foreground color of the scroll bar control.

• ImeMode : Gets or sets the Input Method Editor (IME) mode supported by this control.
• LargeChange: Gets or sets a value to be added to or subtracted from the Value property when
the scroll box is moved a large distance.
• Maximum : Gets or sets the upper limit of values of the scrollable range (default value 32767).
• Minimum: Gets or sets the lower limit of values of the scrollable range (by default 0).
• SmallChange: Gets or sets the value to be added to or subtracted from the Value property
when the scroll box is moved a small distance.
• Value: Gets or sets a numeric value that represents the current position of the scroll box on the
scroll bar control.
Methods of the ScrollBar Control

OnClick : Generates the Click event.

Select: Activates the control.


Events of the ScrollBar Control

• Click : Occurs when the control is clicked.


• DoubleClick: Occurs when the user double-
clicks the control.
• Scroll: Occurs when the control is moved.
• ValueChanged: Occurs when the Value
property changes, either by handling the Scroll
event or programmatically.
Option Explicit

Dim oldPos As Integer

Private Sub cmdQuit_Click()


Unload Me
End Sub

Private Sub Form_Load()


Dim iFullFormHeigth As Integer
Dim iDisplayHeight As Integer

iFullFormHeigth = 3765
iDisplayHeight = 1800

Me.Height = iDisplayHeight

With VScroll1
.Height = Me.ScaleHeight
.Min = 0
.Max = iFullFormHeigth - iDisplayHeight
.SmallChange = Screen.TwipsPerPixelY * 10
.LargeChange = .SmallChange
End With
End Sub
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
End If
Next

oldPos = VScroll1.Value
End Sub

Private Sub VScroll1_Change()


Call pScrollForm
End Sub

Private Sub VScroll1_Scroll()


Call pScrollForm
End Sub

You might also like