ToolStripRenderer.OnRenderToolStripBackground(ToolStripRenderEventArgs) ToolStripRenderer.OnRenderToolStripBackground(ToolStripRenderEventArgs) ToolStripRenderer.OnRenderToolStripBackground(ToolStripRenderEventArgs) ToolStripRenderer.OnRenderToolStripBackground(ToolStripRenderEventArgs) Method

Definición

Genera el evento RenderToolStripBackground.Raises the RenderToolStripBackground event.

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)

Parámetros

Ejemplos

En el ejemplo de código siguiente se muestra cómo OnRenderToolStripBackground invalidar el método para pintar un degradado en ToolStrip el fondo de un control.The following code example demonstrates how to override the OnRenderToolStripBackground method to paint a gradient in the background of a ToolStrip control. Este ejemplo de código forma parte de un ejemplo más extenso proporcionado ToolStripRenderer para la clase.This code example is part of a larger example provided for the ToolStripRenderer class.

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

Comentarios

Cuando se genera un evento, se invoca el controlador de eventos a través de un delegado.Raising an event invokes the event handler through a delegate. Para obtener más información, consulte controlar y provocar eventos.For more information, see Handling and Raising Events.

El método OnRenderToolStripBackground también permite que las clases derivadas controlen el evento sin adjuntar ningún delegado.The OnRenderToolStripBackground method also allows derived classes to handle the event without attaching a delegate. Ésta es la técnica preferida para controlar el evento en una clase derivada.This is the preferred technique for handling the event in a derived class.

Notas a los desarrolladores de herederos

Al reemplazar OnRenderToolStripBackground(ToolStripRenderEventArgs) en una clase derivada, asegúrese de llamar al método OnRenderToolStripBackground(ToolStripRenderEventArgs) de la clase base para que los delegados registrados reciban el evento.When overriding OnRenderToolStripBackground(ToolStripRenderEventArgs) in a derived class, be sure to call the base class's OnRenderToolStripBackground(ToolStripRenderEventArgs) method so that registered delegates receive the event.

Se aplica a

Consulte también: