Lesson X
Lesson X
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.
Notes
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.
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).
Lesson in Action
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.
50
1. Create the Form displayed above.
2. Drag a Label control to the Form and set the following properties:
Name lblBanner
Caption Visual Basic
FontSize 8
FontStyle Arial
BackColor Yellow
On your Own
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.
51