StatusBar::OnDrawItem Method (StatusBarDrawItemEventArgs^)
Raises the OnDrawItem event.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Parameters
- 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 = gcnew StringFormat; // Format the String of the StatusBarPanel to be centered. sf->Alignment = StringAlignment::Center; sf->LineAlignment = StringAlignment::Center; // Draw a back blackground 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 ); }
Available since 1.1