TSlider
Fuente: source/classes/slider.prg
Inherits from: TControl
TSlider provides a trackbar / slider control for selecting a numeric value by dragging a thumb along a track. It supports horizontal and vertical orientation, tick marks, snap-to-grid (exact) positioning, and a slim style with a colored thumb.
Command Syntax
@ nRow, nCol SLIDER oSld VAR nValue RANGE nMin, nMax SIZE nW, nH PIXEL OF oWnd ;
HORIZONTAL MARKS nMarks EXACT ON CHANGE bBlock
Key DATA Members
| DATA | Type | Description |
|---|---|---|
lHorizontal | Logical | Horizontal orientation (.T.) or vertical (.F.) |
nMin | Numeric | Minimum value of the slider range |
nMax | Numeric | Maximum value of the slider range |
nMarks | Numeric | Number of tick marks along the track (0 = no marks) |
lExact | Logical | Snap the thumb to the nearest tick mark |
nClrBtn | Numeric | Color of the slider thumb button |
lSlimStyle | Logical | Render with a slim track and colored thumb |
nDirection | Numeric | Tick mark direction (1=top, 2=left, 3=bottom, 4=right) |
Methods
| Method | Description |
|---|---|
New( nRow, nCol, bSetGet, lHorizontal, lDirect1, lDirect2, nMin, nMax, nMarks, lExact, oWnd, bChange, bPos, nWidth, nHeight, lPixel, cMsg, nClrFore, nClrBack, nClrBtn, lDesign, lUpdate, lSlim ) | Create a new TSlider control |
ReDefine( nId, bSetGet, lHorizontal, lDirect1, lDirect2, nMin, nMax, nMarks, lExact, oWnd, bChange, bPos, cMsg, nClrFore, nClrBack, nClrBtn, lUpdate, lSlim ) | Redefine from dialog resource |
Set( nVal ) | Programmatically set the slider to a value |
Change() | Execute bChange code block with the current value |
Default() | Recalculate positions and redraw |
Examples
Volume Slider (0-100)
#include "FiveWin.ch"
function Main()
local oWnd, oSld, nVolume := 50
DEFINE WINDOW oWnd TITLE "Volume Slider" SIZE 400, 150
@ 40, 30 SLIDER oSld VAR nVolume RANGE 0, 100 ;
SIZE 300, 30 PIXEL OF oWnd HORIZONTAL ;
ON CHANGE oWnd:SetText( "Volume: " + Str( nVolume, 3 ) + "%" )
ACTIVATE WINDOW oWnd CENTERED
return nil
Selector with Tick Marks
#include "FiveWin.ch"
function Main()
local oWnd, oSld, nOption := 3, aOpts := { "Low", "Med", "Norm", "High", "Max" }
DEFINE WINDOW oWnd TITLE "Speed Selector" SIZE 400, 150
@ 40, 30 SLIDER oSld VAR nOption RANGE 1, 5 ;
SIZE 300, 30 PIXEL OF oWnd HORIZONTAL ;
MARKS 5 EXACT ;
ON CHANGE oWnd:SetText( "Speed: " + aOpts[ nOption ] )
ACTIVATE WINDOW oWnd CENTERED
return nil
Notes
- The slider is a self-drawn GDI control, not the Windows common trackbar. This ensures consistent appearance across Windows versions and provides the slim style option.
- When
MARKS nMarksis specified together withEXACT, the thumb snaps to the nearest tick mark position, providing discrete step behavior. - Slim style (
lSlimStyleor theSLIMclause) renders a thinner track with a colored thumb (defaults to CLR_BLUE) for a modern appearance. - Keyboard navigation: Left/Up decrements the value, Right/Down increments it. Page Up/Page Down jump by larger steps.
- The control supports both mouse dragging and click-to-position interaction. Dragging the thumb produces real-time value updates via the
bChangecode block.