Delphi: ComboBox Add Icon To Items

procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
var
  AnIcon : TIcon;
begin
  AnIcon := TIcon.Create;
  try
    VirtualImageList1.GetIcon(55,AnIcon);
    with Control as TComboBox do
    begin
      Canvas.Draw(Rect.Left,Rect.Top,AnIcon);
      Canvas.TextOut(Rect.Left + VirtualImageList1.Width,Rect.Top,Items[Index]);
    end;
  finally
    AnIcon.Free;
  end;
end;

Change Style to csOwnerDrawFixed and set ItemHeight.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s