Monday, September 19, 2011

Menambahkan Image pada Combo Box

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ImgList, StdCtrls;

type
  TForm1 = class(TForm)
    ImageList1: TImageList;
    ComboBox1: TComboBox;
    procedure ComboBox1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    procedure ComboBox1Change(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
     ComboBox1.Canvas.FillRect(Rect);
     ImageList1.Draw(ComboBox1.Canvas,Rect.Left,Rect.Top,Index);
     ComboBox1.Canvas.TextOut(Rect.Left+ImageList1.Width+2,Rect.Top,
                          ComboBox1.Items[Index]);
end;

end.

No comments:

Post a Comment