Share via


ToolStripRenderer.OnRenderToolStripBackground Metode

Definisi

Memunculkan kejadian 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)

Parameter

e
ToolStripRenderEventArgs

ToolStripRenderEventArgs yang berisi data peristiwa.

Contoh

Contoh kode berikut menunjukkan cara mengambil OnRenderToolStripBackground alih metode untuk melukis gradien di latar belakang ToolStrip kontrol. Contoh kode ini adalah bagian dari contoh yang lebih besar yang disediakan untuk ToolStripRenderer kelas .

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

Keterangan

Menaikkan peristiwa memanggil penanganan aktivitas melalui delegasi. Untuk informasi selengkapnya, lihat Menangani dan Meningkatkan Peristiwa.

Metode ini OnRenderToolStripBackground juga memungkinkan kelas turunan untuk menangani peristiwa tanpa melampirkan delegasi. Ini adalah teknik yang disukai untuk menangani peristiwa di kelas turunan.

Catatan Bagi Inheritor

Saat mengambil alih di kelas turunan OnRenderToolStripBackground(ToolStripRenderEventArgs) , pastikan untuk memanggil metode kelas OnRenderToolStripBackground(ToolStripRenderEventArgs) dasar sehingga delegasi terdaftar menerima peristiwa tersebut.

Berlaku untuk

Lihat juga