本例效果圖:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls;
type
TForm1 = class(TForm)
TreeView1: TTreeVIEw;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
CheckBox3: TCheckBox;
CheckBox4: TCheckBox;
CheckBox5: TCheckBox;
CheckBox6: TCheckBox;
TrackBar1: TTrackBar;
procedure FormCreate(Sender: TObject);
procedure CheckBox1Click(Sender: TObject);
procedure CheckBox2Click(Sender: TObject);
procedure CheckBox3Click(Sender: TObject);
procedure CheckBox4Click(Sender: TObject);
procedure CheckBox5Click(Sender: TObject);
procedure CheckBox6Click(Sender: TObject);
procedure TrackBar1Change(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
stream: TStream;
node: TTreeNode;
begin
TreeVIEw1.Align := alLeft;
stream := TMemoryStream.Create;
with TStringList.Create do begin
Add('一連長');
Add(' 一排長');
Add(' 一班長');
Add(' 戰士1');
Add(' 戰士2');
Add(' 戰士3');
Add(' 戰士4');
Add(' 二班長');
Add(' 三班長');
Add(' 二排長');
Add(' 三排長');
Add('二連長');
Add('三連長');
SaveToStream(stream);
Free;
end;
stream.Position := 0;
TreeVIEw1.LoadFromStream(stream);
stream.Free;
CheckBox1.Caption := 'AutoExpand';
CheckBox1.Checked := False;
CheckBox2.Caption := 'HotTrack';
CheckBox2.Checked := False;
CheckBox3.Caption := 'ReadOnly';
CheckBox3.Checked := False;
CheckBox4.Caption := 'ShowButtons';
CheckBox4.Checked := True;
CheckBox5.Caption := 'ShowLines';
CheckBox5.Checked := True;
CheckBox6.Caption := 'ShowRoot';
CheckBox6.Checked := True;
TrackBar1.ShowSelRange := False;
TrackBar1.TickStyle := tsNone;
TrackBar1.Max := 100;
end;
procedure TForm1.CheckBox1Click(Sender: TObject);
begin
TreeVIEw1.AutoExpand := TCheckBox(Sender).Checked;
end;
procedure TForm1.CheckBox2Click(Sender: TObject);
begin
TreeVIEw1.HotTrack := TCheckBox(Sender).Checked;
end;
procedure TForm1.CheckBox3Click(Sender: TObject);
begin
TreeVIEw1.ReadOnly := TCheckBox(Sender).Checked;
end;
procedure TForm1.CheckBox4Click(Sender: TObject);
begin
TreeVIEw1.ShowButtons := TCheckBox(Sender).Checked;
end;
procedure TForm1.CheckBox5Click(Sender: TObject);
begin
TreeVIEw1.ShowLines := TCheckBox(Sender).Checked;
end;
procedure TForm1.CheckBox6Click(Sender: TObject);
begin
TreeVIEw1.ShowRoot := TCheckBox(Sender).Checked;
end;
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
TreeVIEw1.Indent := TrackBar1.Position;
end;
end.