Search code examples
delphidelphi-7trackbar

How to adjust a TrackBar thumb size?


I can't adjust a TTrackBar thumb size to a higher size. See the image:

Trackbar thumb is small (on the left)

I got a small thumb on the left, and I can't make it bigger (but not the TrackBar itself).
Desired thumb size is shown on an image with a red area.
Maybe I can use WINAPI somehow? C++ apps have bigger thumb often.

This is what I'm actually hopping for:

NotePad++ TrackBar style


Solution

  • It would seem like this cannot be done with the standard trackbar control. Indeed, I cannot see any trackbar style or trackbar message related to this. There is only the TBM_SETTHUMBLENGTH, which you also can access from VCL's TTrackBar.ThumbLength, but this also affects the height of the background sunken rectangle.

    A corollory is that I doubt the observation that "C++ apps have bigger thumb often".

    Of course, you can always make your own trackbar-like control.

    Or do you only want to shrink the sunken rectangle? Then just set ShowSelRange to False in the Object Inspector. But if themes are on, you still cannot make the thumb bigger than about 24.

    If you are on an old version of Delphi with no TrackBar.ShowSelRange, you need to remove the window style TBS_ENABLESELRANGE manually. You can do this at any time using SetWindowLong, or you can do it in CreateParams of a subclassed trackbar control. The simplest way might be to use an 'interposer class':

    type
      TTrackBar = class(ComCtrls.TTrackBar)
      protected
        procedure CreateParams(var Params: TCreateParams); override;
      end;
    
    ...   
    implementation
    
    { TTrackBar }
    
    procedure TTrackBar.CreateParams(var Params: TCreateParams);
    begin
      inherited;
      Params.Style := Params.Style and not TBS_ENABLESELRANGE;
    end;
    

    To get the appearance in the Notepad++ screenshot, you should also set TickMarks to tmBoth and TickStyle to tsNone.

    This doesn't answer your question, though, which was about making the thumb larger. This will make the sunken rectangle smaller... From your screenshots, however, I would guess this is what you want.