segunda-feira, 23 de novembro 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;
Bmp.Loadfromfile('c:chip16.bmp');
Bmp1:=TBitmap.Create;
Bmp.Loadfromfile('c:zoom.bmp');
Bmp1:=TBitmap.Create;
Bmp.Loadfromfile('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]);
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;

Colocando BMP's em StringGrids
with StringGrid1.Canvas do
begin
{...}
Draw(Rect.Left, Rect.Top, Image1.Picture.Graphic);
{...}
end;

Nenhum comentário:

Postar um comentário