Share via


Command.AddControl-Methode

Aktualisiert: November 2007

Erstellt ein persistentes Befehlsleisten-Steuerelement für den Befehl.

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

Syntax

Function AddControl ( _
    Owner As Object, _
    Position As Integer _
) As CommandBarControl

Dim instance As Command
Dim Owner As Object
Dim Position As Integer
Dim returnValue As CommandBarControl

returnValue = instance.AddControl(Owner, _
    Position)
CommandBarControl AddControl(
    Object Owner,
    int Position
)
CommandBarControl^ AddControl(
    [InAttribute] Object^ Owner, 
    [InAttribute] int Position
)
function AddControl(
    Owner : Object, 
    Position : int
) : CommandBarControl

Parameter

  • Owner
    Typ: System.Object

    Erforderlich. Ein Microsoft.VisualStudio.CommandBars.CommandBar-Objekt, dem das neue Befehlsleisten-Steuerelement hinzugefügt werden soll.

  • Position
    Typ: System.Int32

    Optional. Die Indexposition auf der Befehlsleiste (beginnend bei Eins), an der das neue Steuerelement eingefügt werden soll.

Rückgabewert

Typ: Microsoft.Office.Core.CommandBarControl

Ein Microsoft.VisualStudio.CommandBars.CommandBarControl-Objekt.

Hinweise

Das Steuerelement und seine Position werden von der Umgebung gespeichert. Diese werden entsprechend den ContextUIGUIDs des Befehls oder den Antworten auf die QueryStatus Method-Methode in allen neuen Sitzungen der Umgebung verfügbar gemacht, unabhängig davon, ob das Add-In geladen wird.

Beispiele

' Macro code.
Imports Microsoft.Office.Core
Sub AddControlExample()
   ' Before running, you must add a reference to
   ' Microsoft.VisualStudio.CommandBars. Also, 
   ' for this example to work correctly, there should be an add-in 
   ' available in the Visual Studio environment.
   Dim cmds As Commands
   Dim cmdobj As Command
   Dim customin, customout As Object
   Dim cmdbarobj As CommandBar
   Dim colAddins As AddIns

   ' Set references.
   colAddins = DTE.AddIns()
   cmds = DTE.Commands
   cmdobj = cmds.Item("File.NewFile")

   ' Create a toolbar and add the File.NewFile command to it.
   cmdbarobj = cmds.AddCommandBar("MyCmdBar", vsCommandBarType.vsCommandBarTypeToolbar)
   MsgBox("Commandbar name: " & cmdbarobj.Name)
   cmdobj.AddControl(cmdbarobj)
   cmds.AddNamedCommand(colAddins.Item(1), "MyCommand", "Button Text", "Some tooltip", True)
End Sub

Berechtigungen

Siehe auch

Referenz

Command-Schnittstelle

Command-Member

EnvDTE-Namespace