Cita:
Empezado por bulc
El problema es que en el Canvas del ListBox no quedan bien alineados Imagen-Texto. Las imágenes se agolpan unas sobre otras.
|
Hola bulc.
O estoy entendiendo mal tu problema, o la solución es ajustar la propiedad
ItemHeight del ListBox a la altura de las imágenes al inicio:
Código Delphi
[-]
ListBox1.ItemHeight := ImageList1.Height;
Por ejemplo:
Código Delphi
[-]
...
procedure TForm1.FormCreate(Sender: TObject);
var
i: Integer;
begin
with ListBox1 do
begin
Columns:= 1;
Style:= lbOwnerDrawFixed;
for i:= 0 to 9 do
Items.Add('Item '+IntToStr(i));
Font.Size := 24; ItemHeight:= ImageList1.Height; end;
end;
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
with TListBox(Control) do
begin
Canvas.FillRect(Rect);
ImageList1.Draw(Canvas, Rect.Left, Rect.Top, Index);
Canvas.TextOut(Rect.Left + ImageList1.Width + 10,
((Rect.Top+Rect.Bottom)div 2)-(Font.Size div 2), Items[Index]);
end;
end;
...
Da este resultado:
Saludos.