学习 TTreeView [10] - AutoExpand、HotTrack、ReadOnly、ShowButtons、ShowLines、ShowRoot、Indent
学习 TTreeView [10] - AutoExpand、HotTrack、ReadOnly、ShowButtons、ShowLines、ShowRoot、Indent
涂孟超 发表于3年前
学习 TTreeView [10] - AutoExpand、HotTrack、ReadOnly、ShowButtons、ShowLines、ShowRoot、Indent
  • 发表于 3年前
  • 阅读 4
  • 收藏 0
  • 点赞 0
  • 评论 0

腾讯云 技术升级10大核心产品年终让利>>>   

本例效果图:


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.

 
 
 
 
 

 

 

  
共有 人打赏支持
粉丝 13
博文 2004
码字总数 14107
×
涂孟超
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: