ToolStripManager.FindToolStrip(String) Method

Definition

Finds the specified ToolStrip or a type derived from ToolStrip.

C#
public static System.Windows.Forms.ToolStrip FindToolStrip(string toolStripName);
C#
public static System.Windows.Forms.ToolStrip? FindToolStrip(string toolStripName);

Parameters

toolStripName
String

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

Returns

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

Examples

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

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

Remarks

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.

Applies to

Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10