ListBox.MeasureItem Event

 

Occurs when an owner-drawn ListBox is created and the sizes of the list items are determined.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

member MeasureItem : IEvent<MeasureItemEventHandler,
    MeasureItemEventArgs>

You can create an event handler for this event to specify the size an item will be made before it is drawn in the DrawItem event. The event is only raised when the DrawMode property is set to OwnerDrawVariable.

The maximum valid height of a ListBox item is 255 pixels. Setting the ItemHeight property of the MeasureItemEventArgs to a value greater than 255 when handling this event may yield unexpected results.

For more information about handling events, see Handling and Raising Events.

The following code example demonstrates an owner-drawn ListBox by setting the DrawMode property to OwnerDrawVariable and handling the DrawItem and MeasureItem events. It also demonstrates setting the BorderStyle and ScrollAlwaysVisible properties and using the AddRange method.

To run this example, paste it in an empty form that imports the System.Drawing namespace and the System.Windows.Forms namespace. Call InitializeOwnerDrawnListBox from the form's constructor or Load event-handling method.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1
Return to top
Show: