ToolStripRenderer.OnRenderToolStripBackground Metodo

Definizione

Genera l'evento RenderToolStripBackground.

protected:
 virtual void OnRenderToolStripBackground(System::Windows::Forms::ToolStripRenderEventArgs ^ e);
protected virtual void OnRenderToolStripBackground(System.Windows.Forms.ToolStripRenderEventArgs e);
abstract member OnRenderToolStripBackground : System.Windows.Forms.ToolStripRenderEventArgs -> unit
override this.OnRenderToolStripBackground : System.Windows.Forms.ToolStripRenderEventArgs -> unit
Protected Overridable Sub OnRenderToolStripBackground (e As ToolStripRenderEventArgs)

Parametri

e
ToolStripRenderEventArgs

Oggetto ToolStripRenderEventArgs contenente i dati dell'evento.

Esempio

Nell'esempio di codice seguente viene illustrato come eseguire l'override del OnRenderToolStripBackground metodo per disegnare una sfumatura nello sfondo di un ToolStrip controllo . Questo esempio di codice fa parte di un esempio più ampio fornito per la ToolStripRenderer classe .

// This method renders the GridStrip control's background.
protected override void OnRenderToolStripBackground(
    ToolStripRenderEventArgs e)
{
    base.OnRenderToolStripBackground(e);

    // This late initialization is a workaround. The gradient
    // depends on the bounds of the GridStrip control. The bounds 
    // are dependent on the layout engine, which hasn't fully
    // performed layout by the time the Initialize method runs.
    if (this.backgroundBrush == null)
    {
        this.backgroundBrush = new LinearGradientBrush(
           e.ToolStrip.ClientRectangle,
           SystemColors.ControlLightLight,
           SystemColors.ControlDark,
           90,
           true);
    }

    // Paint the GridStrip control's background.
    e.Graphics.FillRectangle(
        this.backgroundBrush, 
        e.AffectedBounds);
}
' This method renders the GridStrip control's background.
Protected Overrides Sub OnRenderToolStripBackground(e As ToolStripRenderEventArgs)
   MyBase.OnRenderToolStripBackground(e)
   
   ' This late initialization is a workaround. The gradient
   ' depends on the bounds of the GridStrip control. The bounds 
   ' are dependent on the layout engine, which hasn't fully
   ' performed layout by the time the Initialize method runs.
   If Me.backgroundBrush Is Nothing Then
      Me.backgroundBrush = New LinearGradientBrush(e.ToolStrip.ClientRectangle, SystemColors.ControlLightLight, SystemColors.ControlDark, 90, True)
   End If
   
   ' Paint the GridStrip control's background.
   e.Graphics.FillRectangle(Me.backgroundBrush, e.AffectedBounds)
  End Sub

Commenti

La generazione di un evento richiama il gestore eventi tramite un delegato. Per altre informazioni, vedere Gestione e generazione di eventi.

Il OnRenderToolStripBackground metodo consente anche alle classi derivate di gestire l'evento senza associare un delegato. Questa è la tecnica preferita per gestire l'evento in una classe derivata.

Note per gli eredi

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

Si applica a

Vedi anche