StatusBar.DrawItem Zdarzenie

Definicja

Występuje, gdy zmienia się wizualny aspekt kontrolki paska stanu narysowanego przez właściciela.

public:
 event System::Windows::Forms::StatusBarDrawItemEventHandler ^ DrawItem;
public event System.Windows.Forms.StatusBarDrawItemEventHandler DrawItem;
member this.DrawItem : System.Windows.Forms.StatusBarDrawItemEventHandler 
Public Custom Event DrawItem As StatusBarDrawItemEventHandler 

Typ 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

To zdarzenie służy do wykonywania operacji rysunkowych w kontrolce narysowanej StatusBar przez właściciela. Jeśli na przykład zostanie wyświetlony narysowany StatusBarPanel przez właściciela pasek postępu, możesz użyć tego zdarzenia do wykonania rysunku paska postępu na panelu. Dane dostarczone do zdarzenia za pośrednictwem StatusBarDrawItemEventArgs obiektu przekazanego jako parametr do programu obsługi zdarzeń umożliwiają określenie panelu, który musi zostać narysowany i Graphics używany do rysowania do panelu. To zdarzenie jest zgłaszane tylko wtedy, gdy StatusBarPanel.Style właściwość kontrolki StatusBarPanel jest ustawiona StatusBar na OwnerDraw.

Aby uzyskać więcej informacji na temat obsługi zdarzeń, zobacz Obsługa i podnoszenie zdarzeń.

Dotyczy

Zobacz też