Condividi tramite


ToolStripManager.FindToolStrip(String) Metodo

Definizione

Trova il controllo ToolStrip specificato o un tipo derivato da 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

Parametri

toolStripName
String

Stringa che specifica il nome del controllo ToolStrip o del tipo ToolStrip derivato da trovare.

Restituisce

ToolStrip

Controllo ToolStrip o uno dei relativi tipi derivati come specificato dal parametro toolStripName oppure null se ToolStrip non viene trovato.

Esempio

Nell'esempio di codice seguente viene illustrato un uso del FindToolStrip metodo. Questo esempio fa parte di un esempio più grande fornito per la Renderer proprietà.

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

Commenti

Utilizzare il FindToolStrip metodo per cercare un ToolStrip oggetto o derivato da ToolStrip. I tipi derivati di ToolStrip sono StatusStrip, , ToolStripDropDownMenuStrip, ToolStripDropDownMenue ContextMenuStrip. Se l'oggetto della ricerca non è specificamente un ToolStrip ma uno di questi tipi derivati, eseguire il cast del tipo restituito in base alle esigenze.

Si applica a