ToolStripRenderer.OnRenderToolStripBackground Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Eleva o RenderToolStripBackground evento.
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
A ToolStripRenderEventArgs que contém os dados do evento.
Exemplos
O exemplo de código seguinte demonstra como sobrescrever o OnRenderToolStripBackground método para pintar um gradiente no fundo de um ToolStrip controlo. Este exemplo de código faz parte de um exemplo maior fornecido para a ToolStripRenderer classe.
// 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
Observações
Levantar um evento invoca o gestor de eventos através de um delegado. Para mais informações, consulte Manuseio e Levantamento de Eventos.
O OnRenderToolStripBackground método também permite que classes derivadas tratem do evento sem anexar um delegado. Esta é a técnica preferida para lidar com o evento numa classe derivada.
Notas para Herdeiros
Ao substituir OnRenderToolStripBackground(ToolStripRenderEventArgs) uma classe derivada, certifique-se de chamar o método da OnRenderToolStripBackground(ToolStripRenderEventArgs) classe base para que os delegados registados recebam o evento.