Skip to main content

TcxCustomTrackBarProperties.OnDrawThumb Event

Enables you to paint the track bar’s thumb in a custom manner.

Declaration

property OnDrawThumb: TcxDrawThumbEvent read; write;

Remarks

You can custom paint the track bar’s thumb by setting the ThumbType property to cxttCustom and handling the OnDrawThumb event.

The Sender parameter specifies the control whose thumb is painted. The ACanvas parameter allows you to obtain the canvas where you need to paint. The bounding rectangle of the track bar’s thumb is obtained via the ARect parameter. Note that the width and height of this rectangle (the size of the thumb) must be specified via an OnGetThumbRect event handler.

The sample code below handles the OnDrawThumb and OnGetThumbRect events to paint an image instead of the track bar’s thumb.

procedure <Form>.<cxTrackBar>PropertiesGetThumbRect(Sender: TObject; var ARect: TRect);
var
  Bitmap: TBitmap;
begin
  Bitmap := TBitmap.Create;
  Bitmap.LoadFromFile('c:\ThumbImage.bmp');
  ARect := Rect(0, 0, Bitmap.Width, Bitmap.Height);
end;
procedure <Form>.<cxTrackBar>PropertiesDrawThumb(Sender: TObject; ACanvas: TcxCanvas; const ARect: TRect);
var
  Bitmap: TBitmap;
begin
  Bitmap := TBitmap.Create;
  Bitmap.LoadFromFile('c:\ThumbImage.bmp');
  ACanvas.Draw(ARect.Left, ARect.Top, Bitmap);
end;

The result of handling these events is shown in the image below.

See Also