首页  编辑  

如何在ListView控件中绘底图

Tags: /超级猛料/VCL/ListView/   Date Created:

ListViewؼWindows򿪷еijÿؼ, ԰ҪûѡĶĿڴбķʽʾ, ÿһĿСͼʹͼ, ӶԸƳû, û.

---- ΪʹĽ, ǻListViewؼлƵͼ, ǿΪڻƵͼһ. Delphi, ΪListViewؼƵͼǷdz׵, ΪṩOnCustomDraw¼, רڴûԶĻ, ڸ¼бд, ڻListViewĸĿ֮ǰ, ִи¼ListViewĻ(Canvas)ϻԼͼ.

---- ListViewؼлͼһС, нͼʾ()

---- Դ:

unit ListViewMain;

interface

uses

Windows, Messages, SysUtils, Classes, Graphics,

 Controls, Forms, Dialogs,

 ComCtrls, ImgList;

type

 TForm1 = class(TForm)

   ListView1: TListView;

   ImageList1: TImageList;

procedure ListView1CustomDraw(Sender:

TCustomListView;

     const ARect: TRect; var DefaultDraw:

    Boolean);

   procedure FormCreate(Sender: TObject);

procedure FormClose(Sender: TObject;

var Action: TCloseAction);

 private

   { Private declarations }

 public

   { Public declarations }

 end;

var

 Form1: TForm1;

 Bitmap1: TBitmap;

implementation

{$R *.DFM}

procedure TForm1.ListView1CustomDraw(Sender:

TCustomListView;

 const ARect: TRect; var DefaultDraw: Boolean);

var

  x,y,w,h : LongInt;

begin

 with Bitmap1 do begin

   W := Width;

   H := Height;

 end;

 Y := 0;

 while Y < Height do begin

   X := 0;

   while X < Width do begin

     ListView1.Canvas.Draw(X, Y, Bitmap1);

     Inc(X, W);

   end;

   Inc(Y, H);

 end;

end;

procedure TForm1.FormCreate(Sender: TObject);

begin

 Bitmap1 := TBitmap.Create;

 Bitmap1.LoadFromFile('backgray.bmp');

end;

procedure TForm1.FormClose(Sender: TObject;

 var Action: TCloseAction);

begin

 Bitmap1.Free;

end;

end.