StatusBar.OnDrawItem(StatusBarDrawItemEventArgs) Metoda

Definicja

protected:
 virtual void OnDrawItem(System::Windows::Forms::StatusBarDrawItemEventArgs ^ sbdievent);
protected virtual void OnDrawItem (System.Windows.Forms.StatusBarDrawItemEventArgs sbdievent);
abstract member OnDrawItem : System.Windows.Forms.StatusBarDrawItemEventArgs -> unit
override this.OnDrawItem : System.Windows.Forms.StatusBarDrawItemEventArgs -> unit
Protected Overridable Sub OnDrawItem (sbdievent As StatusBarDrawItemEventArgs)

Parametry

sbdievent
StatusBarDrawItemEventArgs

Element StatusBarDrawItemEventArgs zawierający dane zdarzenia.

Przykłady

Poniższy przykład kodu przedstawia sposób tworzenia rysunku StatusBarPanel właściciela, który wyświetla niestandardowe tło i bieżącą datę. W tym przykładzie wymagane jest połączenie DrawItem zdarzenia kontrolki z procedurą StatusBar obsługi zdarzeń zdefiniowaną w przykładzie.

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 );
   }
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 Sub StatusBar1_DrawItem(ByVal sender As Object, ByVal sbdevent As System.Windows.Forms.StatusBarDrawItemEventArgs) Handles StatusBar1.DrawItem

   ' Create a StringFormat object to align text in the panel.
   Dim sf As 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, _
         New RectangleF(sbdevent.Bounds.X, sbdevent.Bounds.Y, _
         sbdevent.Bounds.Width, sbdevent.Bounds.Height), sf)
End Sub

Uwagi

Podnoszenie zdarzenia wywołuje program obsługi zdarzeń przez delegata. Aby uzyskać więcej informacji, zobacz Obsługa i podnoszenie zdarzeń.

Metoda OnDrawItem umożliwia również klasom pochodnym obsługę zdarzenia bez dołączania delegata. Jest to preferowana technika obsługi zdarzenia w klasie pochodnej.

Uwagi dotyczące dziedziczenia

Podczas zastępowania OnDrawItem(StatusBarDrawItemEventArgs) w klasie pochodnej należy wywołać metodę klasy OnDrawItem(StatusBarDrawItemEventArgs) bazowej, aby zarejestrowani delegaci otrzymywali zdarzenie.

Dotyczy

Zobacz też