Export (0) Print
Expand All

ToolStripManager.FindToolStrip Method

Finds the specified ToolStrip or a type derived from ToolStrip.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

[UIPermissionAttribute(SecurityAction.Demand, Window = UIPermissionWindow.AllWindows)]
public static ToolStrip FindToolStrip(
	string toolStripName
)

Parameters

toolStripName
Type: System.String

A string specifying the name of the ToolStrip or derived ToolStrip type to find.

Return Value

Type: System.Windows.Forms.ToolStrip
The ToolStrip or one of its derived types as specified by the toolStripName parameter, or null if the ToolStrip is not found.

Use the FindToolStrip method to search for a ToolStrip or an object derived from ToolStrip. Derived types of ToolStrip are StatusStrip, MenuStrip, ToolStripDropDown, ToolStripDropDownMenu, and ContextMenuStrip. If the object of the search is not specifically a ToolStrip but one of these derived types, cast the return type as required.

The following code example demonstrates a use of the FindToolStrip method. This example is part of a larger example provided for the Renderer property.

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

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft