Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Create Owner-Draw List and Combo Boxes with .NET

Learn to use the DrawMode settings with ListBoxes and ComboBoxes to create and display customized items.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

ou create an "owner-draw" ListBox or ComboBox when you want to bypass the control's automatic item display in order to do something special, such as display an image for each item or display a list in which the items aren't all the same size. The .NET framework makes it simple to create these custom item lists. In this article, you'll see how to populate list and combobox controls with items you draw yourself.

The only thing you need to do to create an owner-drawn list or combo box is to set the DrawMode property to either OwnerDrawFixed, or OwnerDrawVariable. The DrawMode property has three possible settings: Normal (the default), in which the system handles displaying the items automatically; OwnerDrawFixed, which you should use when you want to draw the items yourself, but they're all the same height and width; and OwnerDrawVariable, which you use to draw items that vary in height or width. When you select the OwnerDrawFixed setting, you must implement a DrawItem method, which the ListBox calls whenever it needs to draw an item. When you select the OwnerDrawVariable setting, you must implement both the DrawItem and a MeasureItem method. The MeasureItem method lets you set the size of the item to be drawn. When you select the Normal setting, the system does not fire either the MeasureItem or the DrawItem methods.

There are a couple of restrictions. You can't create variable-height items for multicolumn ListBoxes, and CheckedListBoxes don't support either of the owner-drawn DrawMode settings.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date