delphi TreeView的问题
有两个 Treeview 在两个不同的Tab页中!因为tab页需要来回切换!我希望第一个 treeview 中选择某一个节点后,这个节点有一个明显的显示!比如 红色!或者其他的方式,当用户切换到另一个tab页后再切换回来时 ,仍能看见他刚才选择的节点是哪一个?请问怎么实现?
[解决办法]
DrawItem事件中画选中节点的背景色
[解决办法]
这里有个ListBox的,Treeview类似,也是在
DrawItem事件中
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
with ListBox1.Canvas do
begin
if (odSelected in State) then Brush.Color:=clWhite;
Font.Color := clBlue;
FillRect(Rect);
TextOut(Rect.Left,Rect.top,ListBox1.Items[index]);
end;
end;
[解决办法]
procedure TForm1.ListView1Click(Sender: TObject);VAR _RECT : TRECT;begin if listview1.selcount>0 THEN BEGIN _RECT:=listview1.Selected.DisplayRect(drSelectBounds); WITH LISTVIEW1.Canvas DO BEGIN Font.Color:=clBackground; BRUSH.Color:=CLRED; FillRect(_RECT); TextOut(LISTVIEW1.Selected.LEFT+LISTVIEW1.Columns[0].Width-12, LISTVIEW1.Selected.TOP+2, LISTVIEW1.SELECTED.SubItems.Strings[0]); END; END;end;