Вы находитесь на странице: 1из 2

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.

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.

Example of a Horizontal Scrollbar (Left) and a Vertical Scrollbar (Right)

The following are the fundamental properties of a scrollbar.


Property
LargeChang
e
Max
Min
SmallChang
e
Value

Description
Specifies the amount that the scrollbars Value property
changes when the user clicks within the scrollbars shaft
area.
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)
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.
Specifies the amount that the scrollbars Value property
changes when the user clicks an arrow at either end of the
scrollbar.
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
Lets 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 ScrollBars Value will
subsequently change the FontSize of the Label.

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
3.

4.

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
Labels caption.
Write the following procedure:

Private Sub hsbFSize_Change()


LblBanner.FontSize = hsbFSize.Value
End Sub
5. Run your application.
6. Save your work as Lesson10.vbp.

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.

Вам также может понравиться