unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls;
type
TForm1 = class(TForm)
ImageList1: TImageList;
ListView1: TListView;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure ListView1CustomDrawItem(Sender: TCustomListView; Item: TListItem;
State: TCustomDrawState; var DefaultDraw: Boolean);
private
FUnderlay: TBitmap;
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
var
Png: TPortableNetworkGraphic;
I: Integer;
const
ImageWidth = 128;
ImageHeight = 128;
begin
FUnderlay := TBitmap.Create;
FUnderlay.SetSize(ImageWidth, ImageHeight);
FUnderlay.PixelFormat := pf24Bit;
FUnderlay.Canvas.Brush.Style := bsSolid;
FUnderlay.Canvas.Brush.Color := clGreen;
FUnderlay.Canvas.FillRect(0, 0, FUnderlay.Width, FUnderlay.Height);
ImageList1.Width := ImageWidth;
ImageList1.Height := ImageHeight;
Png := TPortableNetworkGraphic.Create;
try
Png.LoadFromFile(ExtractFilePath(ParamStr(0)) + '/test.png');
ImageList1.Add(Png, nil);
ImageList1.Add(Png, nil);
ImageList1.Add(Png, nil);
ImageList1.Add(Png, nil);
ImageList1.Add(Png, nil);
ImageList1.Add(Png, nil);
ImageList1.Add(Png, nil);
ImageList1.Add(Png, nil);
ImageList1.Add(Png, nil);
finally
Png.Free;
end;
for I := 0 to ImageList1.Count - 1 do
begin
with ListView1.Items.Add do
begin
Caption := 'item' + I.ToString;
ImageIndex := I;
end;
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FUnderlay.Free;
end;
procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
var
R: TRect;
begin
R := Item.DisplayRect(drBounds); // causes slowdown ???
Sender.Canvas.Draw(R.Left, R.Top, FUnderlay);
DefaultDraw := False;
end;
end.