Главная страница | назад





Article #17056: Customizing TTrackBar

 Question and Answer Database

FAQ2056D.txt   Customizing TTrackBar
Category   :VCL
Platform    :All
Product    :All 32 bit  

Question:
How can I create a trackbar where the track has a thin line on
which the slider moves along, rather than a rather big white 
space which the slider moves along?


Answer:
The following example demonstrates creating a descendant of 
the TTrackbar component that overrides the CreateParams 
method, and clears the TBS_ENABLESELRANGE flag from the 
params style. This results in a Trackbar component that has a 
small thin track for the slider to move upon. Note that the 
TBS_ENABLESELRANGE constant is declared in the CommCtrl unit.

Example:

uses CommCtrl, ComCtrls;

type TMyTrackBar = class(TTrackBar)
  procedure CreateParams(var Params: TCreateParams); override;
end;

procedure TMyTrackBar.CreateParams(var Params: TCreateParams);
begin
  inherited;
  Params.Style := Params.Style and not TBS_ENABLESELRANGE;
end;

var
  MyTrackbar : TMyTrackbar;

procedure TForm1.Button1Click(Sender: TObject);
begin
  MyTrackBar := TMyTrackbar.Create(Form1);
  MyTrackbar.Parent := Form1;
  MyTrackbar.Left := 100;
  MyTrackbar.Top := 100;
  MyTrackbar.Width := 150;
  MyTrackbar.Height := 45;
  MyTrackBar.Visible := true;
end;

7/16/98 4:31:28 PM
 

Last Modified: 01-SEP-99