ComboBox - colocando bitmaps usando o addobject |
Top Previous Next |
|
// Ajuste a propriedade Style do ComboBox para csOwnerDrawVariable.
var Form1: TForm1; Bmp1, Bmp2, Bmp3: TBitmap;
implementation
{$R *.DFM}
colocar no ComboBox1.Style = csOwnerDrawVariable
procedure TForm1.FormCreate(Sender: TObject); begin Bmp1:=TBitmap.Create; Bmp1.Loadfromfile('c:\1.bmp'); Bmp2:=TBitmap.Create; Bmp2.Loadfromfile('c:\2.bmp'); Bmp3:=TBitmap.Create; Bmp3.Loadfromfile('c:\3.bmp'); ComboBox1.Items.AddObject('Chip',Bmp1); ComboBox1.Items.AddObject('Zoom',Bmp2); ComboBox1.Items.AddObject('Disk',Bmp3); end;
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); var Bitmap: TBitmap; Offset: Integer; begin with (Control as TComboBox).Canvas do begin FillRect(Rect); Bitmap:= TBitmap(ComboBox1.Items.Objects[index]); if Bitmap<>nil then begin BrushCopy(Bounds(Rect.Left + 2, Rect.Top + 2, Bitmap.Width, Bitmap.Height), Bitmap, Bounds(0, 0, Bitmap.Width, Bitmap.Height), clRed); Offset:= Bitmap.width + 8; end; TextOut(Rect.Left + Offset, Rect.Top, ComboBox1.Items[index]); end; end;
procedure TForm1.ComboBox1MeasureItem(Control: TWinControl; Index: Integer; var Height: Integer); begin Height := 20; end; |