ToolStripRenderer.OnRenderToolStripBackground Metoda

Definice

RenderToolStripBackground Vyvolá událost.

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)

Parametry

e
ToolStripRenderEventArgs

A ToolStripRenderEventArgs , který obsahuje data události.

Příklady

Následující příklad kódu ukazuje, jak přepsat metodu OnRenderToolStripBackground pro vykreslení přechodu na pozadí ToolStrip ovládacího prvku. Tento příklad kódu je součástí většího příkladu ToolStripRenderer pro třídu .

// 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

Poznámky

Vyvolání události spustí obslužnou rutinu události prostřednictvím delegáta. Další informace najdete v tématu Zpracování a vyvolávání událostí.

Metoda OnRenderToolStripBackground také umožňuje odvozeným třídám zpracovat událost bez připojení delegáta. Toto je upřednostňovaná technika pro zpracování události v odvozené třídě.

Poznámky pro dědice

Při přepsání OnRenderToolStripBackground(ToolStripRenderEventArgs) v odvozené třídě nezapomeňte volat metodu základní třídy OnRenderToolStripBackground(ToolStripRenderEventArgs) , aby registrovaní delegáti obdrželi událost.

Platí pro

Viz také