ToolStripRenderer.OnRenderToolStripBackground メソッド

定義

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)

パラメーター

e
ToolStripRenderEventArgs

イベント データを含む ToolStripRenderEventArgs

次のコード例では、 OnRenderToolStripBackground メソッドをオーバーライドして、 ToolStrip コントロールの背景にグラデーションを描画する方法を示します。 このコード例は、 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

注釈

イベントを発生させると、デリゲートを介してイベント ハンドラーが呼び出されます。 詳細については、「イベントの 処理と発生」を参照してください。

OnRenderToolStripBackground メソッドでは、デリゲートをアタッチせずに、派生クラスでイベントを処理することもできます。 これは、派生クラスでイベントを処理するために推奨される手法です。

注意 (継承者)

派生クラスで OnRenderToolStripBackground(ToolStripRenderEventArgs) をオーバーライドする場合は、登録されているデリゲートがイベントを受け取るように、基底クラスの OnRenderToolStripBackground(ToolStripRenderEventArgs) メソッドを必ず呼び出してください。

適用対象

こちらもご覧ください