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 che contiene i dati dell'evento.

Esempio

Nell'esempio di codice seguente viene illustrato come eseguire l'override del OnRenderToolStripBackground metodo per disegnare una sfumatura in background di un ToolStrip controllo. Questo esempio di codice fa parte di un esempio più grande 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

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 OnRenderToolStripBackground 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 OnRenderToolStripBackground(ToolStripRenderEventArgs) in una classe derivata, verificare di chiamare il metodo OnRenderToolStripBackground(ToolStripRenderEventArgs) della classe di base in modo che i delegati registrati ricevano l'evento.

Si applica a

Vedi anche