Creates a persistent command bar control for the command.
Namespace: EnvDTE
Assembly: EnvDTE (in envdte.dll)
Visual Basic (Declaration)
Function AddControl ( _
<InAttribute> Owner As Object, _
<InAttribute> <OptionalAttribute> Optional Position As Integer = 1 _
) As Object
Dim instance As Command
Dim Owner As Object
Dim Position As Integer
Dim returnValue As Object
returnValue = instance.AddControl(Owner, Position)
Object AddControl (
[InAttribute] Object Owner,
[OptionalAttribute] [InAttribute] int Position
)
Object^ AddControl (
[InAttribute] Object^ Owner,
[InAttribute] [OptionalAttribute] int Position
)
Object AddControl (
/** @attribute InAttribute() */ Object Owner,
/** @attribute InAttribute() */ /** @attribute OptionalAttribute() */ int Position
)
function AddControl (
Owner : Object,
Position : int
) : Object
Parameters
- Owner
Required. A Microsoft.VisualStudio.CommandBars.CommandBar object to which the new command bar control is to be added.
- Position
Optional. The index position, starting at one, in the command bar to place the new control.
Return Value
A Microsoft.VisualStudio.CommandBars.CommandBarControl object.
The environment saves the control and its placement, making it available according to the command's ContextUIGUIDs or its responses to QueryStatus Method during each new session of the environment, regardless of whether the Add-in is loaded.
' 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