看看这样,还有点问题,改一下吧
procedure TForm1.FormCreate(Sender: TObject);
begin
FBkBmp:=TBitmap.Create;
FBkBmp.LoadFromFile('D:/Shuzi/Resource/图标/背景/Gone Fishing.bmp');
FBKBmp.Transparent:=True;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FBkBmp.Free;
end;
procedure TForm1.ListView1CustomDraw(Sender: TCustomListView;
const ARect: TRect; var DefaultDraw: Boolean);
begin
Sender.Brush.Bitmap:=FBkBmp;
Sender.Canvas.Brush.Bitmap:=FBkBmp;
Sender.Canvas.FillRect(ARect);
end;
procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
var
i,x:integer;
Images:TCustomImageList;
R:TRect;
begin
with Sender as TListView do
begin
if ViewStyle=vsIcon then
Images:=LargeImages
else
Images:=SmallImages;
if Images<>nil then
begin
R:=Item.DisplayRect(drIcon);
ImageList_DrawEx(Images.Handle, Item.ImageIndex, Canvas.Handle,
R.Left+(R.Right-R.Left-Images.Width) div 2,
R.Top+(R.Bottom-R.Top-Images.Height) div 2,0, 0,
clNone, clNone, ILD_Transparent);
end;
R:=Item.DisplayRect(drLabel);
if cdsSelected in State then
begin
Canvas.Brush.Style := bsSolid;
SetTextColor(Canvas.Handle,clWhite);
SetBkColor(Canvas.Handle,clNavy);
SetBkMode(Canvas.Handle,Windows.OPAQUE);
Canvas.TextRect(R,R.Left,R.Top,Item.Caption);
if RowSelect and (ViewStyle=vsReport) then
begin
R:=Item.DisplayRect(drBounds);
R.Left:=R.Left+Columns[0].Width;
Canvas.Brush.Color := clNavy;
Canvas.FillRect(R);
end;
end
else
begin
Canvas.Brush.Style:=bsClear;
SetBkMode(Canvas.Handle,Windows.TRANSPARENT);
Canvas.TextRect(R,R.Left,R.Top,Item.Caption);
end;
if ViewStyle=vsReport then
begin
Canvas.Brush.Style:=bsClear;
SetBkMode(Canvas.Handle,Windows.TRANSPARENT);
R:=Item.DisplayRect(drBounds);
X:=R.Left+Columns[0].Width+Item.Indent;
for i:=0 to Item.SubItems.Count-1 do
begin
Canvas.TextRect(R,X,R.Top,Item.SubItems);
X:=X+Columns[i+1].Width+Item.Indent;
end;
end;
DefaultDraw:=False;
end;
end;