{自定义TreeView的CustomDrawItem事件,根据用户的类型显示不同的颜色,图标等}
procedure TForm1.TrevUserListCustomDrawItem(
Sender: TCustomTreeView; Node: TTreeNode; State: TCustomDrawState;
var DefaultDraw: Boolean);
var
G1:TBITMAP;
begin
try
G1:= TBITMAP.Create;
if fileexists(EXTRACTFILEPATH(APPLICATION.ExeName)+'\1.BMP') then
G1.LoadFromFile(EXTRACTFILEPATH(APPLICATION.ExeName)+'\1.BMP')
else
g1:=nil;
DefaultDraw:=true;
if Node.Selected then
begin
TrevUserList.Canvas.Font.Color:=clWhite;
IF node.Parent <> nil then begin
if (g1 <> nil) and havideo and (node.Parent.Text='正常') then
TrevUserList.Canvas.Draw(100,Node.DisplayRect(True).Top,G1);
end;
end
else
begin
if Node.StateIndex = 2 then
begin
if (Node.ImageIndex = 6) or (Node.ImageIndex = 10) then
TrevUserList.Canvas.Font.Color:=clRed
else begin
TrevUserList.Canvas.Font.Color:=clGreen;
IF g1 <> nil then begin
if havideo then
TrevUserList.Canvas.Draw(100,Node.DisplayRect(True).Top,G1);
end;
end;
end
else if Node.StateIndex = -1 then
begin
TrevUserList.Canvas.Font.Color:=$00934A46;
TrevUserList.Canvas.Font.Style:=[fsBold];
end
else
TrevUserList.Canvas.Font.Color:=clBlack;