Using HTrackBars and VTrackBars

The HTrackBar and VTrackBar controls have sliders that move in discrete increments inside a horizontal or vertical channel. Like a scroll bar, a track bar typically functions as a slider control that allows users to specify a value or see a value you have displayed graphically, but on a discrete rather than continuous scale. Clicking on the slider moves it in discrete increments instead of continuously.

NoteSmartphone platforms Avoid using track bars in applications that you deploy to a Smartphone device or emulator. User interaction with these controls is problematic on Smartphone platforms.

Setting properties and placing tick marks

Use a track bar when you want the user to select a discrete value. For example, you might use a track bar to enable a user to select a timer interval or the size of a window.

You can set properties such as minimum and maximum values. You can also set the frequency of tick marks and where tick marks display. Typically a horizontal track bar has a series of tick marks along the bottom of the channel, and a vertical track bar has tick marks on the right.

Highlighting a range of values

You can highlight a range of values in the trackbar with the SelectionRange function. The range you select is indicated by a black fill in the channel and an arrow at each end of the range. This is useful if you want to indicate a range of preferred values. In a scheduling application, the selection range could indicate a block of time that is available for scheduling purposes. Setting a selection range does not prevent the user from selecting a value either inside or outside the range.

Figure 11-6: Horizontal track bar with a highlighted range

Shown is a group box labeled Select Automatic Update Frequency. It includes the words Lower and Higher on either side of a light-colored track bar with tick marks along its bottom edge. The track bar includes a down arrow that the user can slide right or left along the scale to change the value. A dark area in the middle of the track bar represents a selection range. Text at the bottom reads "For best results, select a frequency in the highlighted range."