本例效果图:
![](https://www.cnblogs.com/images/cnblogs_com/del/124874/o_83133.gif)
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.