Lesson X. Horizontal
and Vertical Scrollbars
Objectives
ü To be
able to use Horizontal and Vertical Scrollbar controls to select from ranges of
values.
ü To be
able to use Scrollbars to manipulate other controls.
![]()
Scrollbars let users control value changes. Rather than type specific values, the user can move the scrollbar with the mouse to specify relative positions within a range of values. There are two types of scrollbars: Horizontal and Vertical Scrollbars. Except for their orientation, they share exactly the same properties.

Example of a Horizontal Scrollbar
(Left) and a Vertical Scrollbar (Right)
The following are the fundamental
properties of a scrollbar.
|
Property |
Description |
|
LargeChange |
Specifies the amount that the
scrollbar’s Value property changes when the user clicks within the
scrollbar’s shaft area. |
|
Max |
Indicates the maximum number of
units that the scrollbar value represents at its highest setting. The range is from 1 to 32,767 (the default
Max value) |
|
Min |
Indicates the minimum number of
units the scrollbar value represents at its lowest setting. The range is from
1 (the default Min value) to 32,767. |
|
SmallChange |
Specifies the amount that the
scrollbar’s Value property changes when the user clicks an arrow at either
end of the scrollbar. |
|
Value |
Contains the units of measurement
currently represented by the position of the scrollbar. |
When you place a scrollbar on a Form,
set the range of values the scrollbar is to represent. Set the Min and Max property to
the lowest and highest value the scrollbar will represent, respectively. When the user eventually clicks any arrow
in the scrollbar, the Value of the scrollbar will change (positive SmallChange
when the right or up arrow is clicked; negative SmallChange when the
left or down arrow is clicked).
Let’s use the ScrollBar in
a simple application. In the Form
below, the ScrollBar will be used to manipulate the font size of the Label. The main task is simply to associate the Value
property of the scrollbar to the FontSize property of the Label. Thus, changing the ScrollBar’s Value
will subsequently change the FontSize of the Label.

1. Create the Form displayed above.
1.
Drag a Label control to the Form and set the following
properties:
§
Name lblBanner
§
Caption Visual
Basic
§
FontSize 8
§
FontStyle Arial
§
BackColor Yellow
2.
Drag a HScrollBar to the Form and set the
following properties:
§
Name hsbFSize
§
Min 8
§
Max 35
§
Value 8
The Max value
also determines the maximum font size of the label. Tip: Assign the maximum font size of the caption that can
fit within the Label to the Value property of the HScrollBar. The initial value of the Value
property should match the initial FontSize of the Label’s
caption.
3.
Write the following procedure:
Private Sub hsbFSize_Change()
LblBanner.FontSize = hsbFSize.Value
End Sub
4.
Run your application.
5.
Save your work as Lesson10.vbp.
1.
Create a program that manipulates the position of the Label
in the Form using Vertical and Horizontal Scrollbars. Note: Make sure that the Label does not go
beyond the rectangular Shape control.

2.
Modify the program you have made in the Lesson in Action
section. Display the current font size
in a Label.
[ Home ]