Freigeben über


ToolBoxItems.Add-Methode

Erstellt ein neues Element und fügt es der ToolBox hinzu.

Namespace:  EnvDTE
Assembly:  EnvDTE (in EnvDTE.dll)

Syntax

'Declaration
Function Add ( _
    Name As String, _
    Data As Object, _
    Format As vsToolBoxItemFormat _
) As ToolBoxItem
ToolBoxItem Add(
    string Name,
    Object Data,
    vsToolBoxItemFormat Format
)
ToolBoxItem^ Add(
    [InAttribute] String^ Name, 
    [InAttribute] Object^ Data, 
    [InAttribute] vsToolBoxItemFormat Format
)
abstract Add : 
        Name:string * 
        Data:Object * 
        Format:vsToolBoxItemFormat -> ToolBoxItem
function Add(
    Name : String, 
    Data : Object, 
    Format : vsToolBoxItemFormat
) : ToolBoxItem

Parameter

  • Name
    Typ: String

    Erforderlich. Eine Zeichenfolge, die die Beschriftung des neuen Elements darstellt.

  • Data
    Typ: Object

    Erforderlich. Eine Variante, die die Zeichenfolge, das Steuerelement oder ein anderes Element darstellt, das der ToolBox hinzugefügt werden soll.

Rückgabewert

Typ: EnvDTE.ToolBoxItem
Ein ToolBoxItem-Objekt.

Hinweise

Diese Methode verursacht einen Fehler, wenn die ToolBoxItems-Auflistung zu einem gelöschten ToolBoxTab-Objekt gehört oder wenn Sie versuchen, eine Registerkarte mit einem bereits vorhandenen Namen hinzuzufügen.

Für das Data-Argument können Visual C++-Benutzer IUnknown von IDataObject übergeben.

Beim Hinzufügen einer Assembly mit dem Format vsToolBoxItemFormatDotNETComponent kann der an den Data-Parameter übergebene Name eines der folgenden Formate aufweisen:

  • <AssemblyPath> – wobei "<AssemblyPath>" einem Pfad- und Dateinamen entspricht, der auf eine verwaltete Assembly zeigt, beispielsweise C:\Libraries\MyAssembly.dll. Wenn Sie dieses Format verwenden, werden der ToolBox alle Klassen innerhalb der DLL hinzugefügt.

  • <AssemblyNameInTheGAC> – eine einzelne Klasse, die als von der Assembly qualifizierter Verweis aufgeführt ist. Einzelne Klassen können als Steuerelemente hinzugefügt werden, sofern sie Verweise auf eine Assembly im globalen Assemblycache sind, z. B. WindowControlLibrary1.UserControl1, WindowControlLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=<Your Token>. (Sie müssen <Your Token> durch Ihr Token des öffentlichen Schlüssels ersetzen, damit die Assembly dem GAC hinzugefügt wird.)

Beispiele

Im folgenden Beispiel wird veranschaulicht, wie der ToolBox ein Textdokument hinzugefügt wird:

Sub ToolBoxAddExample1()
    ' This adds a Text item to the first tab of the ToolBox.
    ' Define the variables and create an object reference to the IDE's  
    ' ToolBox object.
    Dim win As Window = DTE.Windows.Item(Constants.vsWindowKindToolbox)
    Dim tlbox As ToolBox = win.Object
    Dim tbxTabs As ToolBoxTabs

    ' Create an object reference to the ToolBoxTabs object.
    tbxTabs = tlbox.ToolBoxTabs

    ' Add a new Text item to the first tab in the ToolBox.
    tbxTabs.Item(1).ToolBoxItems.Add("New Text Item", "Some text to _
    add to the document.", vsToolBoxItemFormat.vsToolBoxItemFormatText)
End Sub

Im folgenden Beispiel wird veranschaulicht, wie der ToolBox eine .NET-Komponente unter Verwendung eines Pfads zur Datei hinzugefügt wird. Bei der Komponente, die hinzugefügt werden soll, muss es sich um ein .NET-Steuerelement handeln, z. B. eine Komponente der Windows-Steuerelementbibliothek von Visual Basic.

Sub ToolBoxItemAddExample2()
    Try
        Dim tlBox As ToolBox
        tlBox = CType(DTE.Windows.Item(Constants. _
        vsWindowKindToolbox).Object, EnvDTE.ToolBox)
        ' Create a new tab called "My Controls."
        Dim tlBoxTab As ToolBoxTab = tlBox.ToolBoxTabs. _
        Add("My Controls")
        ' Set focus to the new Toolbox tab.
        tlBoxTab.Activate()
        ' Add a .NET control as a new control in the new ToolBox tab. 
        ' The constant "vsToolBoxItemFormatDotNETComponent" alerts the 
        ' ToolBox to the type of control you are adding.
        tlBoxTab.ToolBoxItems.Add("MyDotNetControl", _
        "C:\Libraries\ADotNetControl.dll(", _
        vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent)
    Catch ex As System.Exception
        ' Display any errors that occur.
        MsgBox("ERROR: " & ex.Message)
    End Try
End Sub

.NET Framework-Sicherheit

Siehe auch

Referenz

ToolBoxItems Schnittstelle

EnvDTE-Namespace

Weitere Ressourcen

Gewusst wie: Steuern der Toolbox