Owner Draw - ComboBox

posted 15 Mar 2010, 14:17 by Delphi Basics
As with menus (menu items), an application can create an owner-drawn combo box to take responsibility for painting list items. An owner-drawn combo box can list/show information other than text strings - usually some graphical elements.

To create an owner-draw combo box, we set its Style property to csOwnerDrawFixed or csOwnerDrawVariable.
  • If all list items in the combo box are the same height, such as strings or icons, an application can use the csOwnerDrawFixed style.
  • If list items are of varying height, like bitmaps of different size, an application can use the csOwnerDrawVariable style. In this case the application will receive the WM_MEASUREITEM Windows message and the OnMeasureItem event will be fired for each item - to specify the height of list items in the combo box.
Having done this, Windows no longer draws the control. Instead it sends a WM_DRAWITEM message whenever a portion of the control needs to be repainted. The parent window (form) of an owner-drawn combo box (its owner) then fires the OnDrawItem event when a portion of the combo box needs to be painted.

To demonstrate owner-drawing with combo boxes create a combo box full of colors (two variations) and a combo with true-type fonts showing the actual image of the font.

Read more: http://delphi.about.com/od/vclusing/a/drawincombobox.htm

To read more about Owner Drawing in Delphi read: http://delphi.about.com/od/vclusing/a/owner_drawing.htm


Only Delphi source code is included in the archive.

ċ
OwnerDrawComboBox.7z
(2k)
Delphi Basics,
15 Mar 2010, 14:20
Comments