程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> TTreeView講解 [10] - AutoExpand、HotTrack、ReadOnly、ShowBu

TTreeView講解 [10] - AutoExpand、HotTrack、ReadOnly、ShowBu

編輯:Delphi

 本例效果圖:

TTreeView講解 [10] - AutoExpand、HotTrack、ReadOnly、ShowButtons、ShowLines、ShowRoot、Indent

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. 


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved