O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Create an Owner-Drawn List Box

Problem

You want to create a list box that includes pictures, formatted text, or colored item backgrounds.

Solution

Set the list box DrawMode to OwnerDrawVariable, and handle the MeasureItem and DrawItem events.

Discussion

By implementing an owner-drawn list box, you can draw custom content in a list box item in the same way that you would draw graphics in a Paint event handler. The only challenge is deciding where to store item-specific graphics or formatting information.

To create a basic owner-drawn list box, set the ListBox.DrawMode property to OwnerDrawVariable (or you can use OwnerDrawFixed if you know that every list item will have the same height). This signals that you want to write the drawing logic for the control. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required