DrawItem Event
Collapse the table of content
Expand the table of content

MenuItem.DrawItem Event

Occurs when the OwnerDraw property of a menu item is set to true and a request is made to draw the menu item.

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

public event DrawItemEventHandler DrawItem

The DrawItemEventArgs argument passed to a DrawItem event handler provides a Graphics object that enables you to perform drawing and other graphical operations on the surface of the menu item. You can use this event handler to create custom menus that meet the needs of your application. For more information about handling events, see Consuming Events.

The following code example demonstrates how to handle the DrawItem event. This example draws a menu item using a Brush and a Font, and then draws a Rectangle around the menu item. The drawing is performed through the Graphics object, which is passed to the event handler in the DrawItemEventArgs parameter. This example requires that you have initialized the OwnerDraw property for the item to true. For the C# example, add the following code in the form's constructor, after InitializeComponent, to hook up the event:

this.menuItem1.DrawItem += new DrawItemEventHandler(menuItem1_DrawItem);

// The DrawItem event handler. 
private void menuItem1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)

	string myCaption = "Owner Draw Item1";

	// Create a Brush and a Font with which to draw the item.
	Brush myBrush = System.Drawing.Brushes.AliceBlue;
	Font myFont = new Font(FontFamily.GenericSerif, 14, FontStyle.Underline, GraphicsUnit.Pixel);
	SizeF mySizeF = e.Graphics.MeasureString(myCaption, myFont);

	// Draw the item, and then draw a Rectangle around it.
	e.Graphics.DrawString(myCaption, myFont, myBrush, e.Bounds.X, e.Bounds.Y);
	e.Graphics.DrawRectangle(Pens.Black, new Rectangle(e.Bounds.X, e.Bounds.Y, Convert.ToInt32(mySizeF.Width), Convert.ToInt32(mySizeF.Height)));


Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

Community Additions

© 2016 Microsoft