ToolStripRenderer.OnRenderToolStripBackground Método
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
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
que ToolStripRenderEventArgs 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 forma parte de un ejemplo más grande proporcionado para la ToolStripRenderer clase .
// 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
La generación de un evento invoca el controlador de eventos a través de un delegado. Para obtener más información, consulte Control y generación de eventos.
El OnRenderToolStripBackground método también permite que las clases derivadas controle el evento sin adjuntar un delegado. Esta es la técnica preferida para controlar el evento en una clase derivada.
Notas a los desarrolladores de herederos
Al invalidar OnRenderToolStripBackground(ToolStripRenderEventArgs) en una clase derivada, asegúrese de llamar al método de OnRenderToolStripBackground(ToolStripRenderEventArgs) la clase base para que los delegados registrados reciban el evento.