注:这里除了给Listview加背景外,而且图标实现了透明效果.
在delphi中我们可以这样实现:
procedure TForm1.ListView1CustomDraw(Sender: TCustomListView;
const ARect: TRect; var DefaultDraw: Boolean);
var
Bitmap : TBitMap;
begin
Bitmap := TBitmap.Create;
Bitmap.LoadFromFile('back.bmp');
ListView1.Canvas.Draw(0,0,Bitmap);
ListView1.Color:=clNone;
SetBkMode(Listview1.Canvas.Handle,TRANSPARENT);//就这里了
listview1.Perform(LVM_SETTEXTBKCOLOR,0,LongInt(CLR_NONE));
ListView_SetBKColor(ListView1.Handle,CLR_NONE);
end;
这是另一段代码:
uses CommCtrl;
procedure TForm1.ListView1CustomDraw(Sender: TCustomListView;
const ARect: TRect; var DefaultDraw: Boolean);
begin
TListView(Sender).Canvas.Draw(0, 0, Image1.Picture.Graphic);
SetBkMode(TListView(Sender).Canvas.Handle, TRANSPARENT);
TListView(Sender).Perform(LVM_SETTEXTBKCOLOR, 0, LongInt(CLR_NONE));
ListView_SetBKColor(TListView(Sender).Handle, CLR_NONE);
当然这样也可以:
procedure TForm1.ListView1CustomDraw(Sender: TCustomListView;
const ARect: TRect; var DefaultDraw: Boolean);
var
x,y: LongInt;
begin
x := self.Width - bitmap1.Width;
y := self.Height - bitmap1.Height;
self.Caption := inttostr(form1.Width) + ',' + inttostr(x);
listview1.Canvas.Draw(x, y, bitmap1);
SetBkMode(listview1.Canvas.Handle,TRANSPARENT);
ListView_SetTextBKColor(listview1.Handle,CLR_NONE);
end;
在C++Builder中我们可以这样写:
void __fastcall TfrmMain::ListView1CustomDraw(TCustomListView *Sender,
const TRect &ARect, bool &DefaultDraw)
{
AnsiString strPath;
strPath=ExtractFilePath(Application->ExeName);
Graphics::TBitmap * bmp=new Graphics::TBitmap();
bmp->LoadFromFile(strPath+"bk.bmp");
ListView1->Canvas->Draw(0,0,bmp);
ListView1->Color=clNone;
SetBkMode(ListView1->Canvas->Handle,TRANSPARENT);
Sender->Perform(LVM_SETTEXTBKCOLOR,0,long(CLR_NONE));
ListView_SetBkColor(Sender->Handle,CLR_NONE);
}
阅读(2452) | 评论(0) | 转发(0) |