Hier ein Beispiel, kannst es testen:
Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
begin
with ListBox1 do
Style := lbOwnerDrawFixed;
end;
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
LB: TListBox;
dTop, dLeft: Integer;
Size: TSize;
begin
if not (Control is TListBox) then Exit;
LB := Control as TListbox;
Size := LB.Canvas.TextExtent(LB.Items[Index]);
dTop := (LB.ItemHeight - Size.cy) div 2;
dLeft := ((Rect.Right - Rect.Left) - Size.cx) div 2;
LB.Canvas.TextRect(Rect, Rect.Left + 2 + dLeft, Rect.Top + dTop, LB.Items[Index]);
end;