ToolStripManager.FindToolStrip(String) 方法

定义

查找指定的 ToolStrip 或从 ToolStrip 派生的类型。

public:
 static System::Windows::Forms::ToolStrip ^ FindToolStrip(System::String ^ toolStripName);
public static System.Windows.Forms.ToolStrip FindToolStrip (string toolStripName);
static member FindToolStrip : string -> System.Windows.Forms.ToolStrip
Public Shared Function FindToolStrip (toolStripName As String) As ToolStrip

参数

toolStripName
String

一个字符串,指定要查找的 ToolStrip 或派生 ToolStrip 类型的名称。

返回

ToolStrip

ToolStrip 或由 toolStripName 参数指定的派生类型之一,如果找不到 ToolStrip,则为 null

示例

下面的代码示例演示了该方法的使用 FindToolStrip 。 此示例是为该属性提供的大型示例的 Renderer 一部分。

// This event handler is invoked when 
// the "Apply Renderers" button is clicked.
// Depending on the value selected in a ComboBox control,
// it applies a custom renderer selectively to
// individual MenuStrip or ToolStrip controls,
// or it applies a custom renderer to the 
// application as a whole.
void applyButton_Click(object sender, EventArgs e)
{
    ToolStrip ms = ToolStripManager.FindToolStrip("MenuStrip");
    ToolStrip ts = ToolStripManager.FindToolStrip("ToolStrip");

    if (targetComboBox.SelectedItem != null)
    {
        switch (targetComboBox.SelectedItem.ToString())
        {
            case "Reset":
            {
                ms.RenderMode = ToolStripRenderMode.ManagerRenderMode;
                ts.RenderMode = ToolStripRenderMode.ManagerRenderMode;

                // Set the default RenderMode to Professional.
                ToolStripManager.RenderMode = ToolStripManagerRenderMode.Professional;

                break;
            }

            case "All":
            {
                ms.RenderMode = ToolStripRenderMode.ManagerRenderMode;
                ts.RenderMode = ToolStripRenderMode.ManagerRenderMode;

                // Assign the custom renderer at the application level.
                ToolStripManager.Renderer = new CustomProfessionalRenderer();

                break;
            }

            case "MenuStrip":
            {
                // Assign the custom renderer to the MenuStrip control only.
                ms.Renderer = new CustomProfessionalRenderer();

                break;
            }

            case "ToolStrip":
            {
                // Assign the custom renderer to the ToolStrip control only.
                ts.Renderer = new CustomProfessionalRenderer();

                break;
            }
        }
    }
}
' This event handler is invoked when 
' the "Apply Renderers" button is clicked.
' Depending on the value selected in a ComboBox 
' control, it applies a custom renderer selectively
' to individual MenuStrip or ToolStrip controls,
' or it applies a custom renderer to the 
' application as a whole.
Sub applyButton_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim ms As ToolStrip = ToolStripManager.FindToolStrip("MenuStrip")
    Dim ts As ToolStrip = ToolStripManager.FindToolStrip("ToolStrip")

    If targetComboBox.SelectedItem IsNot Nothing Then

        Select Case targetComboBox.SelectedItem.ToString()
            Case "Reset"
                ms.RenderMode = ToolStripRenderMode.ManagerRenderMode
                ts.RenderMode = ToolStripRenderMode.ManagerRenderMode

                ' Set the default RenderMode to Professional.
                ToolStripManager.RenderMode = ToolStripManagerRenderMode.Professional

                Exit Select

            Case "All"
                ms.RenderMode = ToolStripRenderMode.ManagerRenderMode
                ts.RenderMode = ToolStripRenderMode.ManagerRenderMode

                ' Assign the custom renderer at the application level.
                ToolStripManager.Renderer = New CustomProfessionalRenderer()

                Exit Select

            Case "MenuStrip"
                ' Assign the custom renderer to the MenuStrip control only.
                ms.Renderer = New CustomProfessionalRenderer()

                Exit Select

            Case "ToolStrip"
                ' Assign the custom renderer to the ToolStrip control only.
                ts.Renderer = New CustomProfessionalRenderer()

                Exit Select
        End Select

    End If
End Sub

注解

FindToolStrip使用该方法搜索派生自ToolStrip的或ToolStrip对象。 派生的类型为 、、、和ToolStripDropDownMenuContextMenuStripToolStripDropDownMenuStripStatusStripToolStrip 如果搜索的对象不是特定 ToolStrip 对象,而是其中一种派生类型,请根据需要强制转换返回类型。

适用于