....
扔个listimage,0位置图片是不选择的,1是选择的
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ImgList;
type
TForm1 = class(TForm)
tv: TTreeView;
ImageList1: TImageList;
procedure FormShow(Sender: TObject);
procedure tvCustomDrawItem(Sender: TCustomTreeView; Node: TTreeNode;
State: TCustomDrawState; var DefaultDraw: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
begin
tv.ShowRoot:=false;
tv.FullExpand;
if tv.Items.Count>0 then
tv.Selected:=tv.Items[0];
end;
procedure TForm1.tvCustomDrawItem(Sender: TCustomTreeView; Node: TTreeNode;
State: TCustomDrawState; var DefaultDraw: Boolean);
var
arect:trect;
bmp:tbitmap;
x,m:integer;
begin
DefaultDraw:=false;
if node.Selected then
sender.Canvas.Brush.Color:=clred
else
sender.Canvas.Brush.Color:=clwindow;
arect:=node.DisplayRect(true);
x:=arect.Left+2;
m:=arect.Bottom-arect.Top;
if node.Level>0 then
begin
arect.Right:=arect.Right+m;
sender.Canvas.FillRect(arect);
bmp:=tbitmap.Create;
imagelist1.GetBitmap(integer(node.Selected),bmp);
sender.Canvas.CopyRect(rect(arect.Left,arect.Top,arect.Left+m,arect.Bottom),
bmp.Canvas,rect(0,0,bmp.Width,bmp.Height));
x:=arect.Left+bmp.Width+2;
bmp.Free;
end;
sender.Canvas.TextOut(x,arect.Top+2,node.Text);
end;
end.