ScrollBars

Windows provides a basic ScrollBar component which can be used on forms for Text, Graphics, Volume Controls, and the like. The slider (thumb tab) is moved via user interaction, your software detects the new position and performs some function. Normally, the size of the slider represents the percentage of the data currently displayed.

I normally prefer the length of a scroll bar to be some logical range minus the width of the slider. This way, when it has moved the maximum amount, some text (or whatever) is still displayed.


Visual Basic 6.0

VisualBasic provides 2 ScrollBar controlls with similar functions

The size of the Slider is automatically adjusted according to the Min, Max, Length, and LargeChange parameters.

Unfortunately, in VB 6, the scrollbars are white - in all other windows applications, they are gray (or what you've configured via the control panel). Also, the various values are stored as integers (+/- ~32,000). In English, that means that it is difficult to control a display with more than ~32,000 rows.


Parameters

Scrollbars can be used for Graphics, Volume Controls, and the like. However, the following examples assume that a vertical scrollbar is being used to control the displaying of a text file. Important events

Delphi

The TScrollBar component is used for both vertical and horizontal ScrollBars. With Delphi 5, the help and examples are very good.


Parameters

The following descriptions assume a vertical ScrollBar. With Delphi 5, PageSize has a design problem - in design mode, with Min=0 and Max=100, I set PageSize=101 and was not able to change it again. Basically, this happens for any value larger than Max. However, in this case 101 is required for the bar to completely fill the slider area (Max + 1 because Min=0). By increasing the Max value, I could then modify it.

The TScrollBar Example states that the range for Min and Max is [0, 65535]. If this is exceeded, then the OnScroll event will fail. This warning is not repeated in the OnScroll help.

Important events


C++ Builder


Windows API

The user program must handle keyboard and mouse input to position the slider (scroll box). The width of the slider can be changed in version 4.0 or later (I don't know what 4.0 refers to either).

You can disable one or both arrows.

Windows automatically hides a ScrollBar if the minimum and maximum values are equal or if the page size includes the entire scroll range.

MaxScrollPos = MaxRangeValue - (PageSize - 1)

Use GetSystemMetrics to get the widths of the related bitmaps.


Author: Robert Clemenzi - clemenzi@cpcug.org
URL: http:// cpcug.org / user / clemenzi / technical / Languages / ScrollBars.htm