Scrollbar Control

Scroll bars provide easy navigation through a long list of items or a large amount of information by scrolling either horizontally or vertically within an application or control. They can also provide an analog representation of current position. You can use a scroll bar as an input device or indicator of speed or quantity—for example, to control the volume of a computer game or to view the time elapsed in a timed process.

Syntax

HScrollBar

VScrollBar

The Scrollbar control has the following properties, methods, and events.

Properties Methods Events
Container Move Change
Enabled Refresh GotFocus
Height, Width SetFocus KeyDown, KeyUp
HWnd ZOrder KeyPress
LargeChange, SmallChange LostFocus
Left Top Scroll
Max, Min
Name
Parent
TabIndex
TabStop
Tag
Value
Visible

Remarks

The horizontal and vertical Scrollbar controls are not the same as the built-in scroll bars found in windows or those that are attached to text boxes, list boxes, or combo boxes. Those scroll bars appear automatically whenever the given application or control contains more information than can be displayed in the current window size (or, in the case of text boxes, when the ScrollBars property is also set to True).

The scroll bar controls use the Scroll and Change events to monitor the movement of the scroll box (sometimes referred to as the thumb) along the scroll bar. Using the Scroll event provides access to the scroll bar value as it is being dragged. The Change event occurs after the scroll box is released or when the scroll bar or scroll arrows are clicked.

The Value property (which, by default, is 0) is an integer value corresponding to the position of the scroll box in the scroll bar. When the scroll box position is at the minimum value, it moves to the leftmost position (for horizontal scroll bars) or the top position (for vertical scroll bars). When the scroll box is at the maximum value, the scroll box moves to the rightmost or bottom position. Similarly, a value halfway between the bottom and top of the range places the scroll box in the middle of the scroll bar.

When you're using a scroll bar as an indicator of quantity or speed or as an input device, use the Max and Min properties to set the appropriate range for the control. Min can be larger than Max if you want your scroll bar to display information changing from a larger to a smaller value.

To specify the amount of change to report in a scroll bar, use the LargeChange property for clicking in the scroll bar, and the SmallChange property for clicking the arrows at the ends of the scroll bar. The scroll bar's Value property increases or decreases by the values set for the LargeChange and SmallChange properties. You can position the scroll box at run time by setting Value between 0 and 32,767, inclusive.