TTrackBar
Fuente: source/classes/trackbar.prg
Inherits from: TControl
TTrackBar wraps the Win32 trackbar common control (slider). It allows the user to select a numeric value by dragging a thumb along a track, with optional tick marks. It is commonly used for volume controls, brightness sliders, and any ranged value input.
Key DATA Members
| DATA | Type | Description |
|---|---|---|
nMin | Numeric | Minimum value of the trackbar range |
nMax | Numeric | Maximum value of the trackbar range |
nPos | Numeric | Current thumb position |
nFreq | Numeric | Tick mark frequency |
bChange | Block | Code block executed when the position changes |
Methods
| Method | Description |
|---|---|
New( nRow, nCol, oWnd, nW, nH, nMin, nMax, nPos, nFreq ) | Create a new trackbar control |
SetPos( n ) | Set the thumb to position n |
GetPos() | Return the current thumb position |
SetRange( nMin, nMax ) | Set the minimum and maximum range values |
SetTicFreq( n ) | Set the tick-mark frequency |
Example: Volume Control 0-255
#include "FiveWin.ch"
function Main()
local oWnd, oTrack, nVol := 128
DEFINE WINDOW oWnd TITLE "Volume Control" SIZE 400, 150
@ 40, 20 TRACKBAR oTrack VAR nVol ;
SIZE 360, 30 OF oWnd ;
RANGE 0, 255 ;
ON CHANGE ( oWnd:SetText( "Volume: " + Str( nVol ) ) )
ACTIVATE WINDOW oWnd CENTERED
return nil
Notes
- TTrackBar wraps the native Win32 trackbar (
TRACKBAR_CLASS). It supports both horizontal and vertical orientations depending on the dimensions passed toNew(). - The
VARclause binds a numeric variable that is updated automatically when the user moves the thumb. - Use
SetTicFreq()to show tick marks at regular intervals. A frequency of 0 hides all tick marks. - The
ON CHANGEclause setsbChange, which fires continuously as the user drags the thumb.