Compartilhar via


StatusBar.OnDrawItem(StatusBarDrawItemEventArgs) Método

Definição

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)

Parâmetros

sbdievent
StatusBarDrawItemEventArgs

Um StatusBarDrawItemEventArgs que contém os dados do evento.

Exemplos

O exemplo de código a seguir demonstra como criar um desenho de proprietário que exibe uma tela de StatusBarPanel fundo personalizada e a data atual. Este exemplo exige que você tenha conectado o DrawItem evento de um StatusBar controle ao manipulador de eventos definido no exemplo.

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

Comentários

A geração de um evento invoca o manipulador de eventos por meio de um delegado. Para obter mais informações, consulte Manipulando e levantando eventos.

O OnDrawItem método também permite que classes derivadas manipulem o evento sem anexar um delegado. Essa é a técnica preferencial para lidar com o evento em uma classe derivada.

Notas aos Herdeiros

Ao substituir OnDrawItem(StatusBarDrawItemEventArgs) em uma classe derivada, chame o método da OnDrawItem(StatusBarDrawItemEventArgs) classe base para que os delegados registrados recebam o evento.

Aplica-se a

Confira também