var
bmp: array[0..2] of TBitmap;
abstand: integer;
procedure TForm1.FormCreate(Sender: TObject);
var x: integer;
begin
Listbox1.Style := lbOwnerDrawVariable;
for x := 0 to 2 do bmp[x] := TBitMap.Create;
bmp[0].loadfromfile('d:\bilder\ledrot.bmp');
bmp[1].loadfromfile('d:\bilder\ledgruen.bmp');
bmp[2].loadfromfile('d:\bilder\ledblau.bmp');
for x := 0 to 2 do bmp[x].transparent := true;
abstand := bmp[0].width + 2;
Listbox1.items.add('Rot');
Listbox1.items.add('Grün');
Listbox1.items.add('Blau');
Listbox1.items.add('ohne Bild');
Listbox1.items.add('ohne Bild');
end;
procedure TForm1.FormDestroy(Sender: TObject);
var x: integer;
begin
for x := 0 to 2 do bmp[x].free;
end;
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
with TListBox(Control).canvas do begin
if odSelected in State then begin
brush.color := $FF8080;
font.color := $80FFFF;
end else begin
brush.color := clwhite;
font.color := clblack;
end;
fillrect(rect);
if index in [0..2] then
draw(rect.left + 1, rect.top + 1, bmp[index]);
inc(rect.left, abstand);
drawtext(handle, pchar(TListBox(Control).items[index]), -1, rect,
DT_VCENTER or DT_SINGLELINE);
end;
end;
procedure TForm1.ListBox1MeasureItem(Control: TWinControl; Index: Integer;
var Height: Integer);
begin
height := bmp[0].height + 2;
end;