OnDrawItem Method

StatusBar.OnDrawItem Method (StatusBarDrawItemEventArgs)


Raises the OnDrawItem event.

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

protected virtual void OnDrawItem(
	StatusBarDrawItemEventArgs sbdievent


Type: System.Windows.Forms.StatusBarDrawItemEventArgs

A StatusBarDrawItemEventArgs that contains the event data.

Raising an event invokes the event handler through a delegate. For more information, see Handling and Raising Events.

The OnDrawItem method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.

Notes to Inheritors:

When overriding OnDrawItem in a derived class, be sure to call the base class's OnDrawItem method so that registered delegates receive the event.

The following code example demonstrates how to create an owner-drawn StatusBarPanel that displays a custom background and the current date. This example requires that you have connected the DrawItem event of a StatusBar control to the event handler defined in the example.

private void DrawMyPanel(object sender, System.Windows.Forms.StatusBarDrawItemEventArgs sbdevent)
   // Create a StringFormat object to align text in the panel.
   StringFormat sf = new StringFormat();
   // Format the String of the StatusBarPanel to be centered.
   sf.Alignment = StringAlignment.Center;
   sf.LineAlignment = StringAlignment.Center;

   // Draw a black background in owner-drawn panel.
   sbdevent.Graphics.FillRectangle(Brushes.Black, sbdevent.Bounds);
   // Draw the current date (short date format) with white text in the control's font.

.NET Framework
Available since 1.1
Return to top
© 2015 Microsoft