添加一些节点:
procedure TForm1.Button1Click(Sender: TObject);
begin
TreeView1.LoadFromFile('D:/temp/delphi/cc.txt')
end;
/////////// 设置 TreeView1 的 OnCustomDrawItem如下:
procedure TForm1.TreeView1CustomDrawItem(Sender: TCustomTreeView;
Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
var
NodeRect: TRect;
begin
with TreeView1.Canvas do
begin
NodeRect := Node.DisplayRect(True);
if cdsSelected in State then
begin
Font.color:=clYellow;
Brush.Color := clRed;
FillRect(NodeRect);
end
else
begin
Brush.Color := clYellow;
end;
FillRect(NodeRect);
TextOut(NodeRect.Left, NodeRect.Top, Node.Text);
end;
end;