How to set custom ticks on TTrackBar in Delphi 2010?

I tried to set the tick style to tsManual, the minimum and maximum positions to 1 and 100, respectively, and add marks at 9, 19, 79 and 89, and no ticks are displayed at all, except for the first and last detonation, which control automatically shows. I tried other values ​​and no one ever showed up. My code is:

TrackBar1.TickStyle := tsManual;
TrackBar1.Min := 1;
TrackBar1.Max := 100;
TrackBar1.SetTick( 9 );
TrackBar1.SetTick( 19 );
TrackBar1.SetTick( 79 );
TrackBar1.SetTick( 89 );

Any suggestions? I am sure that I am missing an important detail, and the documentation is rather scarce. This is the new empty VCL Forms project in Delphi 2010 with Update 4.

Thanks in advance.

+3
source share
3 answers

TTrackBar.SetTick() TBM_SETTIC, Handle :

procedure TTrackBar.SetTick(Value: Integer);
begin
  if HandleAllocated then // <-- here
    SendMessage(Handle, TBM_SETTIC, 0, Value);
end;

, Handle , . , HandleNeeded() SetTick():

TrackBar1.TickStyle := tsManual; 
TrackBar1.Min := 1; 
TrackBar1.Max := 100; 
TrackBar1.HandleNeeed; // <-- here 
TrackBar1.SetTick( 9 ); 
TrackBar1.SetTick( 19 ); 
TrackBar1.SetTick( 79 ); 
TrackBar1.SetTick( 89 );
+5

, TrackBar1.SetTick , SendMessage , , . CommCtrl TBM_SETTIC, ...

implementation

Uses CommCtrl;

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  TrackBar1.TickStyle := tsManual;
  TrackBar1.Min := 0;
  TrackBar1.Max := 100;
  SendMessage(TrackBar1.Handle, TBM_SETTIC, 0, 9);
  SendMessage(TrackBar1.Handle, TBM_SETTIC, 0, 19);
  SendMessage(TrackBar1.Handle, TBM_SETTIC, 0, 79);
  SendMessage(TrackBar1.Handle, TBM_SETTIC, 0, 89);
end;

, !

+2

handle TickStyle= tsManual, frequency , , 1.

0

Source: https://habr.com/ru/post/1734610/


All Articles