共用方式為


ToolStripRenderEventArgs.ToolStrip 屬性

定義

取得要繪製的 ToolStrip

public:
 property System::Windows::Forms::ToolStrip ^ ToolStrip { System::Windows::Forms::ToolStrip ^ get(); };
public System.Windows.Forms.ToolStrip ToolStrip { get; }
member this.ToolStrip : System.Windows.Forms.ToolStrip
Public ReadOnly Property ToolStrip As ToolStrip

屬性值

ToolStrip

要繪製的 ToolStrip

範例

下列程式碼範例示範如何覆寫 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

適用於

另請參閱