Поделиться через


StatusBar.DrawItem Событие

Определение

Происходит при изменении визуального аспекта элемента управления строкой состояния, нарисованной владельцем.

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 

Тип события

Примеры

В следующем примере кода показано, как создать рисунок StatusBarPanel владельца, отображающий настраиваемый фон и текущую дату. В этом примере требуется, чтобы событие StatusBar элемента управления было подключено DrawItem к обработчику событий, определенному в примере.

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

Комментарии

Это событие можно использовать для выполнения операций рисования в нарисованном StatusBar владельцем элементе управления. Например, если отображается нарисованный StatusBarPanel владельцем индикатор хода выполнения, можно использовать это событие для выполнения рисунка индикатора выполнения на панели. Данные, предоставленные событию через StatusBarDrawItemEventArgs объект, переданный в качестве параметра обработчику событий, позволяют определить панель, которую необходимо нарисовать, и Graphics использовать для рисования на панели. Это событие возникает только в том случае, если StatusBarPanel.Style для свойства StatusBarPanel элемента StatusBar управления задано значение OwnerDraw.

Дополнительные сведения об обработке событий см. в разделе "Обработка и создание событий".

Применяется к

См. также раздел