共用方式為


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 的 或 物件。 的 ToolStrip 衍生型別為 StatusStripMenuStripToolStripDropDownToolStripDropDownMenuContextMenuStrip 。 如果搜尋的物件不是特別 ToolStrip 的,而是其中一個衍生型別,請視需要轉換傳回型別。

適用於