ToolStripRenderer.OnRenderToolStripBackground Método

Definición

Genera el 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)

Parámetros

e
ToolStripRenderEventArgs

Objeto ToolStripRenderEventArgs que contiene los datos del evento.

Ejemplos

En el ejemplo de código siguiente se muestra cómo invalidar el OnRenderToolStripBackground método para pintar un degradado en el fondo de un ToolStrip control. Este ejemplo de código es parte de un ejemplo más grande proporcionado para la clase 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

Comentarios

Cuando se genera un evento, se invoca el controlador de eventos a través de un delegado. Para obtener más información, consulte controlar y provocar eventos.

El método OnRenderToolStripBackground también permite que las clases derivadas controlen el evento sin adjuntar ningún delegado. Ésta es la técnica preferida para controlar el evento en una clase derivada.

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.

Se aplica a

Consulte también