domingo, 24 de maio de 2009

Colocando bitmaps num combobox

//Ajuste a propriedade Style do ComboBox para csOwnerDrawVariable.

var
Form1: TForm1;
Bmp1, Bmp2, Bmp3: TBitmap;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
Bmp1:=TBitmap.Create;
Bmp1.Loadfromfile('c:chip16.bmp');
Bmp2:=TBitmap.Create;
Bmp2Loadfromfile('c:zoom.bmp');
Bmp3:=TBitmap.Create;
Bmp3Loadfromfile('c:disk.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]);
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;
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;

Nenhum comentário:

Postar um comentário