StatusBar.OnDrawItem(StatusBarDrawItemEventArgs) Metodo

Definizione

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)

Parametri

sbdievent
StatusBarDrawItemEventArgs

Oggetto StatusBarDrawItemEventArgs che contiene i dati dell'evento.

Esempio

Nell'esempio di codice seguente viene illustrato come creare un proprietario disegnato StatusBarPanel che visualizza uno sfondo personalizzato e la data corrente. In questo esempio è necessario che l'evento DrawItem di un StatusBar controllo sia connesso al gestore eventi definito nell'esempio.

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

Commenti

Quando viene generato un evento, il gestore dell'evento viene richiamato tramite un delegato. Per altre informazioni, vedere la gestione e generazione di eventi.

Il metodo OnDrawItem consente inoltre alle classi derivate di gestire l'evento senza associare un delegato. È la tecnica consigliata per la gestione dell'evento in una classe derivata.

Note per gli eredi

Quando si esegue l'override di OnDrawItem(StatusBarDrawItemEventArgs) in una classe derivata, verificare di chiamare il metodo OnDrawItem(StatusBarDrawItemEventArgs) della classe di base in modo che i delegati registrati ricevano l'evento.

Si applica a

Vedi anche