Owner Draw - ComboBox

Post date: Mar 15, 2010 9:17:02 PM

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.