问题来源: http://www.cnblogs.com/del/archive/2008/06/14/1220638.html#1225896
例一效果图:
例一代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls;
type
TForm1 = class(TForm)
TrackBar1: TTrackBar;
procedure TrackBar1Change(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
Self.Text := IntToStr(TrackBar1.Position);
end;
end.
例二效果图:
例二代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls;
type
TForm1 = class(TForm)
TrackBar1: TTrackBar;
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Button1.Caption := '变';
Button2.Caption := '再变';
Button3.Caption := '还原';
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
TrackBar1.ShowSelRange := False;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
TrackBar1.Orientation := trVertical;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
TrackBar1.ShowSelRange := True;
TrackBar1.Orientation := trHorizontal;
end;
end.
例三效果图:
例三代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ExtCtrls;
type
TForm1 = class(TForm)
TrackBar1: TTrackBar;
Panel1: TPanel;
procedure FormCreate(Sender: TObject);
procedure TrackBar1Change(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
TrackBar1.ShowSelRange := False;
TrackBar1.Min := 1;
TrackBar1.Max := ClientWidth;
TrackBar1.Position := ClientWidth div 2;
TrackBar1.Height := 23;
Panel1.Left := 0;
end;
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
Panel1.Width := TrackBar1.Position;
end;
end.