1. 建立一個窗體
2. 放一個ComboBox和Listbox
3. 改變Component的Style為csOwnerDrawVariable和ListBox的Style為lbOwnerDrawVariable。
4. 聲明5個TBitmap的全局變量
5. 覆蓋Form的OnCreate.
6. 覆蓋ComboBox的OnDraw.
7. 覆蓋ComboBox的OnMeasureItem.
8. 釋放資源在Form的OnClose.
unit Ownerdrw;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls;
type
TForm1 = class(TForm)
ComboBox1: TComboBox;
ListBox1: TListBox;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
procedure ComboBox1MeasureItem(Control: TWinControl; Index: Integer;
var Height: Integer);
procedure ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
procedure ListBox1MeasureItem(Control: TWinControl; Index: Integer;
var Height: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
TheBitmap1, TheBitmap2, TheBitmap3, TheBitmap4,
TheBitmap5 : TBitmap;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
TheBitmap1 := TBitmap.Create;
TheBitmap1.LoadFromFile('C:delphiimagesuttonsglobe.bmp');
TheBitmap2 := TBitmap.Create;
TheBitmap2.LoadFromFile('C:delphiimagesuttonsvideo.bmp');
TheBitmap3 := TBitmap.Create;
TheBitmap3.LoadFromFile('C:delphiimagesuttonsgears.bmp');
TheBitmap4 := TBitmap.Create;
TheBitmap4.LoadFromFile('C:delphiimagesuttonskey.bmp');
TheBitmap5 := TBitmap.Create;
TheBitmap5.LoadFromFile('C:delphiimagesuttons ools.bmp');
ComboBox1.Items.AddObjec