Browse DevX
Sign up for e-mail newsletters from DevX


Create Owner-Draw List and Combo Boxes with .NET  : Page 3

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

Example 2: Drawing Items with Variable Width and Height
Here's another example. The items you create don't all have to be the same width and height. To create an owner-drawn list or combo box with variable item heights and widths, set the DrawMode property to OwnerDrawVariable. Then, implement a method that handles the MeasureItem event, which accepts a sender (Object), and a System.Windows.Forms.MeasureItemEventArgs argument. The sample form frmColorListBox displays all the known system colors and their names in a combo box. The items themselves vary between 20 and 40 pixels in height. It's contrived and ugly (see Figure 2), but serves to illustrate the point.

A. Russell Jones, Ph.D., is DevX's Executive Editor. He's a former reptile keeper and professional musician who now composes computer applications and writes and edits technical articles and books. His most recent books are Mastering ASP.NET with VB.NET and Mastering ASP.NET with Visual C# (both published by Sybex). Reach him by e-mail at rjones@devx.com.
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