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 obsahující data události.

Příklady

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

// 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 vyvolá obslužnou rutinu události prostřednictvím delegáta. Další informace naleznete v tématu Zpracování a vyvolávání událostí.

Metoda OnRenderToolStripBackground také umožňuje odvozené třídy 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 zaregistrovaní delegáti obdrželi událost.

Platí pro

Viz také