Compartir a través de


ToolStripManager.FindToolStrip(String) Método

Definición

Busca el objeto ToolStrip especificado o un tipo derivado de 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

Parámetros

toolStripName
String

Cadena que especifica el nombre del objeto ToolStrip o del tipo de ToolStrip derivado que se va a buscar.

Devoluciones

ToolStrip

Objeto ToolStrip o uno de sus tipos derivados, tal y como se especifica en el parámetro toolStripName, o null si no se encuentra el objeto ToolStrip.

Ejemplos

En el ejemplo de código siguiente se muestra un uso del FindToolStrip método . Este ejemplo forma parte de un ejemplo más grande proporcionado para la Renderer propiedad .

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

Comentarios

Use el FindToolStrip método para buscar un ToolStrip objeto o derivado de ToolStrip. Los tipos derivados de ToolStrip son StatusStrip, MenuStrip, ToolStripDropDown, ToolStripDropDownMenuy ContextMenuStrip. Si el objeto de la búsqueda no es específicamente uno ToolStrip de estos tipos derivados, convierta el tipo de valor devuelto según sea necesario.

Se aplica a