Export (0) Print
Expand All

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.
	an owner-drawn ListBox by setting the the DrawMode property to OwnerDrawVariable value 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.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft