Freigeben über


Gewusst wie: Steuern der Toolbox

Add-Ins für Visual Studio sind in Visual Studio 2013 veraltet. Sie müssen für Ihre Add-Ins ein Upgrade auf VSPackage-Erweiterungen durchführen. Weitere Informationen über das Durchführen eines Upgrades finden Sie unter FAQ: Konvertieren von Add-Ins in VSPackage-Erweiterungen.

Das ToolBox-Objekt wird im Automatisierungsmodell von Visual Studio durch die folgenden Objekte und Auflistungen dargestellt:

Objektname

Beschreibung

ToolBox-Objekt

Stellt die Toolbox dar.

ToolBoxTabs-Auflistung

Stellt alle Registerkarten der Toolbox dar.

ToolBoxTab2-Objekt

Stellt eine Registerkarte der Toolbox dar.

ToolBoxTab3-Objekt

Stellt eine Registerkarte der Toolbox dar.

ToolBoxItem2-Auflistung

Eine Auflistung aller Elemente, die auf einer Registerkarte der Toolbox enthalten sind.

ToolBoxItem-Objekt

Stellt ein einzelnes Element auf einer Registerkarte der Toolbox dar.

Mithilfe dieser Objekte und Auflistungen können Sie folgende Aufgaben ausführen:

  • Hinzufügen einer Registerkarte zur Toolbox (Add-Methode)

  • Aktivieren einer Registerkarte der Toolbox (Activate-Methode)

  • Löschen einer Registerkarte aus der Toolbox (Delete-Methode)

  • Hinzufügen eines Elements zur Toolbox (Add-Methode)

  • Auswählen eines Elements in der Toolbox (Select-Methode)

  • Löschen eines Elements von einer Registerkarte der Toolbox (Delete-Methode)

  • Zur Symbol- oder Listenansicht der Aufgabenliste wechseln (ListView-Eigenschaft)

Außer den Inhalten der Toolbox können auch deren Merkmale, z. B. Breite und Höhe, gesteuert werden. Weitere Informationen finden Sie unter Gewusst wie: Ändern des Erscheinungsbilds eines Fensters.

Hinweis

Je nach den aktiven Einstellungen oder der Version unterscheiden sich die Dialogfelder und Menübefehle auf Ihrem Bildschirm möglicherweise von den in der Hilfe beschriebenen.Bei der Entwicklung dieser Verfahren war die Option "Allgemeine Entwicklungseinstellungen" aktiviert.Wählen Sie im Menü Extras die Option Einstellungen importieren und exportieren aus, um die Einstellungen zu ändern.Weitere Informationen finden Sie unter Anpassen der Entwicklungseinstellungen in Visual Studio.

Beispiel

In diesem Beispiel wird gezeigt, wie die verschiedenen Member des Automatisierungsmodells der Toolbox verwendet werden und wie auf sie verwiesen wird. In diesem Beispiel wird eine neue Registerkarte in der Toolbox erstellt, der dann einige Elemente hinzugefügt werden (u. a. eine .NET-Komponente). Anschließend wird eines der Elemente gelöscht. Optional können Sie die neue Registerkarte auch löschen. Weitere Informationen zum Ausführen des Beispiels finden Sie unter Gewusst wie: Kompilieren und Ausführen der Codebeispiele für das Automatisierungsobjektmodell.

' VSMacro
Sub ToolboxExample()
    Dim tlBox As ToolBox
    Dim tbxTabs As ToolBoxTabs
    Dim tbxTab As ToolBoxTab
    Dim tbxItems As ToolBoxItems
    Dim tbxItem As ToolBoxItem

    Try
        ' Create an object reference to the IDE's ToolBox object and
        ' its tabs.
        tlBox = DTE.Windows.Item(Constants.vsWindowKindToolbox).Object
        tbxTabs = tlBox.ToolBoxTabs

        ' Add a new tab to the Toolbox and select it.
        tbxTab = tbxTabs.Add("New ToolBox Tab")
        tbxTab.Activate()

        ' Add new items to the new Toolbox tab. This shows two
        ' different ways to index the Toolbox tabs. The third item
        ' added is a .NET component that contains a number of 
        ' Web-related controls.
        tbxTab.ToolBoxItems.Add("Text Item", "Hello world")
        tbxTab.ToolBoxItems.Add("HTML Item", "Hello world", _
        vsToolBoxItemFormat.vsToolBoxItemFormatHTML)
        ' Replace the <Path and name of a .NET dll>
        ' with a path to a .NET dll file.
        tbxTabs.Item("New Toolbox Tab").ToolBoxItems.Add _
        ("DotNET Component", "< Path and name of a .NET dll >", _
 vsToolBoxItemFormat. _
        vsToolBoxItemFormatDotNETComponent)
        
        ' Use the ToolboxItems collection to access all the items under 
        ' a ToolBox tab.
        tbxItems = tbxTab.ToolBoxItems

        ' List the number of ToolboxItems in a ToolBoxTab.
        MsgBox _
("Number of items in " & tbxTabs.Item(1).Name & " tab: "  _
& tbxItems.Count)

        ' Select the second item in the ToolboxItems collection and 
        ' delete it.
        tbxItems.Item(2).Select()
        If (MsgBox("Delete the second ToolBox item?", vbYesNo) = vbYes) _
        Then
            tbxItems.SelectedItem.Delete()
            MsgBox("Number of items in " & tbxTabs.Item(1).Name & " _
            tab: " & tbxItems.Count)
        End If
        If (MsgBox("Delete the new tab?", vbYesNo) = vbYes) Then
            tbxTabs.Item("New ToolBox Tab").Delete()
            MsgBox("Tab deleted.")
        End If
    Catch ex As System.Exception
        MsgBox("ERROR: " & ex.Message)
    End Try
End Sub
Using System.Windows.Forms;
public void OnConnection(object application,
 Extensibility.ext_ConnectMode connectMode, object addInInst, ref
 System.Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;
    // Pass the applicationObject member variable to the code example.
    ToolboxExample(_applicationObject); 
}

public void ToolboxExample( DTE2 dte ) 
{ 
    ToolBox tlBox = null; 
    ToolBoxTabs tbxTabs = null; 
    ToolBoxTab3 tbxTab = null; 
    ToolBoxItems tbxItems = null; 
    ToolBoxItem2 tbxItem = null; 

    try 
    { 
        // Create an object reference to the IDE's ToolBox object and
        // its tabs.
        tlBox = (ToolBox )( dte.Windows.Item(
 Constants.vsWindowKindToolbox ).Object ); 
        tbxTabs = tlBox.ToolBoxTabs; 

        // Add a new tab to the Toolbox and select it.
        tbxTab = (ToolBoxTab3)tbxTabs.Add( "New ToolBox Tab" ); 
        tbxTab.Activate(); 

        // Add new items to the new Toolbox tab. This shows two
        // different ways to index the Toolbox tabs. The third item
        // added is a .NET component that contains a number of 
        // Web-related controls.
        tbxTab.ToolBoxItems.Add( "Text Item", "Hello world",
 (EnvDTE.vsToolBoxItemFormat.vsToolBoxItemFormatText)); 
        tbxTab.ToolBoxItems.Add( "HTML Item", "Hello world"
, vsToolBoxItemFormat.vsToolBoxItemFormatHTML ); 
        // Replace the <Path and name of a .NET dll>
        // with a path to a .NET dll file.
        tbxTabs.Item( "New Toolbox Tab" ).ToolBoxItems.Add
( "DotNET Component",
 "<Path and name of a .NET dll>",
 vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent ); 

        // Use the ToolboxItems collection to access all the 
        // items under a ToolBox tab.
        tbxItems = tbxTab.ToolBoxItems; 

        // List the number of ToolboxItems in a ToolBoxTab.
        MessageBox.Show( "Number of items in " +
 tbxTabs.Item( 1 ).Name + " tab: " + tbxItems.Count); 
          
        // Select the second item in the ToolboxItems collection and 
        // delete it.
        // Comment the following lines out, if you do not want to
        // delete the controls.
        tbxItems.Item( 2 ).Select(); 
        
        tbxItems.SelectedItem.Delete(); 
        MessageBox.Show( "Number of items in " 
+ tbxTabs.Item( 1 ).Name + " tab: " + tbxItems.Count); 
        tbxTabs.Item( "New ToolBox Tab" ).Delete(); 
        MessageBox.Show( "Tab deleted."); 
        
    } 
    catch ( System.Exception ex ) 
    { 
        MessageBox.Show( "ERROR: " + ex.Message); 
    } 
}

Sicherheit

Wenn ein COM-Objekt, das registriert werden muss, zur Toolbox hinzugefügt wird, wird die Registrierung der COM-Komponente automatisch ausgeführt. Falls Sie nicht als Administrator (oder als Mitglied der Administratorgruppe) angemeldet sind, schlägt die Registrierung fehl, und das COM-Objekt wird der Toolbox nicht hinzugefügt.

Unabhängig von Ihrer Berechtigungsstufe ist es nicht möglich, nach nicht registrierten COM-Komponenten zu suchen und diese der Toolbox hinzuzufügen.

Siehe auch

Aufgaben

Gewusst wie: Ändern des Erscheinungsbilds eines Fensters

Gewusst wie: Erstellen von Add-Ins

Exemplarische Vorgehensweise: Erstellen eines Assistenten

Konzepte

Diagramm "Automationsobjektmodell"

Weitere Ressourcen

Erstellen und Steuern von Umgebungsfenstern

Erstellen von Add-Ins und Assistenten

Referenz zur Automatisierung und Erweiterbarkeit