1. Create a form 2. Put a ComboBox and ListBox3. Change the composition of the Style for CSOWNERDRAWVARIABLE and Listbox for lbownerdrawvariable. 4. Declare the global variable of 5 Tbitmap 5. Overcome on the Form's oncreate.6. Overdraw.7 of ComboBox. Overwered the ComboBox onMeasureItem.8. Release the resource on the Form's 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: /delphi/images/buttons/globe.bmp'); TheBitmap2: = TBitmap.Create; TheBitmap2.LoadFromFile ( ' C: /delphi/images/buttons/video.bmp '); TheBitmap3: = TBitmap.Create; TheBitmap3.LoadFromFile (' C: /delphi/images/buttons/gears.bmp '); TheBitmap4: = TBitmap.Create; TheBitmap4 .Loadfromfile ('c: /delphi/images/buttons/key.bmp'); thebitmap5: = tbitmap.create; thebitmap5.loadfromfile ('c: /delphi/images/buttons/tools.bmp'); ComboBox1.items. AddObject ( 'bitmap1: Globe', TheBitmap1); ComboBox1.Items.AddObject ( 'Bitmap2: Video', TheBitmap2); ComboBox1.Items.AddObject ( 'Bitmap3: Gears', TheBitmap3); ComboBox1.Items.AddObject (' Bitmap4: Key ', TheBitmap4); ComboBox1.Items.AddObject (' Bitmap5: Tools', TheBitmap5); ListBox1.Items.AddObject ( 'bitmap1: Globe', TheBitmap1); ListBox1.Items.AddObject ( 'Bitmap2: Video', TheBitmap2) ListBox1.Items.addObject ('Bitmap3: gears', thebitmap3); ListBox1.Items.a DDOBJECT ('bitmap4: key', thebitmap4); listbox1.items.addObject ('bitmap5: tools', thebitmap5);
Procedure TFORM1.FORMCLOSE (Sender: Tclosection); begin thebitmap1.free; thebitmap2.free; thebitmap4.free; thebitmap5.free;
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; if Bitmap <> nil dam 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; {Display TEXT} Textout (Rect.Left Offset, Rect.top, ComboBoX1.Items [Index]) END End; Procedure TFORM1.COMBOBOX1MEASUREITEM (Control: TwinControl; index: integer; var height: integer); begin height: = 20;
procedure TForm1.ListBox1DrawItem (Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); var Bitmap: TBitmap; Offset: Integer; begin with (Control as TListBox) .Canvas do begin FillRect (Rect); Bitmap: = Tbitmap (ListBox1.Items.Objects [Index]); if Bitmap <> nil dam brushcopy (Bounds (Rect.L 2, Rect.top 2, Bitmap.width, Bitmap.Height), Bitmap, Bounds (0, 0, Bitmap.Width, Bitmap.Height, CLRED; Offset: = Bitmap.width 8; end; {display the text} textout (Rect.LEFT Offset, Rect.top, ListBox1.Items [index]) END ;
Procedure TForm1.ListBox1measureItem (Control: TwinControl; Index: Integer; Var Height: Integer); Begin Height: = 20;
End.
// DFM file of this form