Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

StatusBar.DrawItem Event

Occurs when a visual aspect of an owner-drawn status bar control changes.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public event StatusBarDrawItemEventHandler DrawItem
/** @event */
public void add_DrawItem (StatusBarDrawItemEventHandler value)

/** @event */
public void remove_DrawItem (StatusBarDrawItemEventHandler value)

In JScript, you can handle the events defined by a class, but you cannot define your own.
Not applicable.

You can use this event to perform drawing operations in an owner-drawn StatusBar control. For example, if you display an owner-drawn StatusBarPanel that displays a progress bar, you can use this event to perform the drawing of the progress bar on the panel. The data provided to the event through the StatusBarDrawItemEventArgs object passed as a parameter to the event handler enables you to determine the panel that needs to be drawn and the Graphics to use to draw to the panel. This event is only raised when the StatusBarPanel.Style property of a StatusBarPanel in a StatusBar control is set to OwnerDraw.

For more information about handling events, see Consuming Events.

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.
   sbdevent.Graphics.DrawString(DateTime.Today.ToShortDateString(), 
      statusBar1.Font,Brushes.White,sbdevent.Bounds,sf);
}

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.set_Alignment(StringAlignment.Center);
    sf.set_LineAlignment(StringAlignment.Center);
    // Draw a back blackground in owner-drawn panel.
    sbdEvent.get_Graphics().FillRectangle(Brushes.get_Black(), 
        sbdEvent.get_Bounds());
    // Draw the current date (short date format) with white text 
    // in the control's font.
    sbdEvent.get_Graphics().DrawString(DateTime.get_Today().
        ToShortDateString(), statusBar1.get_Font(), Brushes.get_White(),
        RectangleF.op_Implicit(sbdEvent.get_Bounds()), sf);
} //DrawMyPanel

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

Show:
© 2014 Microsoft