PDA

Ver la Versión Completa : Pintar en un TListBox o TCheckListBox


dec
30-06-2006, 00:21:49
Ejemplo sobre el TCheckListBox, ya que creo que es mas complejo y se puede aplicar al TListBox con una pequeña modificacion poniendo la propiedad Style en lbOwnerDrawFixed y creando el siguiente Evento


procedure TForm1.CheckListBox1DrawItem(Control: TWinControl;
Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
ABitmap: TBitmap;
begin

ABitmap := TBitmap.Create;
try
ImageList1.GetBitmap( Index, ABitmap );
finally
CheckListBox1.Canvas.FillRect(Rect);
CheckListBox1.Canvas.Draw( 15, Rect.Top, ABitmap );
CheckListBox1.Canvas.TextOut( ABitmap.Width+20, Rect.Top
+( ( Rect.Bottom-Rect.Top
-CheckListBox1.Canvas.TextHeight( CheckListBox1.Items[ Index ] ) ) div 2 )
, CheckListBox1.Items[ Index ] );
end;

end;