I tried to set the tick style to tsManual, the min and max position to 1 and 100 respectively and add ticks at 9, 19, 79 and 89 and no ticks are shown at all except the detault first and last which the control automatically shows. I tried other values and none are ever shown. 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'm sure I'm missing an important detail, and the documentation is pretty sparse. This is on a new empty VCL Forms project in Delphi 2010 with update 4.
Thank you in advance.
TTrackBar.SetTick() does not send the TBM_SETTIC message if the Handle property is currently unassigned:
procedure TTrackBar.SetTick(Value: Integer);
begin
if HandleAllocated then // <-- here
SendMessage(Handle, TBM_SETTIC, 0, Value);
end;
The window handle does not get allocated until the Handle property is read for the first time, not when the component is initially created. As such, call HandleNeeded() before calling SetTick():
TrackBar1.TickStyle := tsManual;
TrackBar1.Min := 1;
TrackBar1.Max := 100;
TrackBar1.HandleNeeded; // <-- here
TrackBar1.SetTick( 9 );
TrackBar1.SetTick( 19 );
TrackBar1.SetTick( 79 );
TrackBar1.SetTick( 89 );