Command.AddControl Method
Creates a persistent command bar control for the command.
Namespace: EnvDTE
Assembly: EnvDTE (in EnvDTE.dll)
Syntax
'Declaration
Function AddControl ( _
Owner As Object, _
Position As Integer _
) As Object
Object AddControl(
Object Owner,
int Position
)
Object^ AddControl(
[InAttribute] Object^ Owner,
[InAttribute] int Position
)
abstract AddControl :
Owner:Object *
Position:int -> Object
function AddControl(
Owner : Object,
Position : int
) : Object
Parameters
- Owner
Type: System.Object
Required. A CommandBar object to which the new command bar control is to be added.
- Position
Type: System.Int32
Optional. The index position, starting at one, in the command bar to place the new control.
Return Value
Type: System.Object
A CommandBarControl object.
Remarks
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.
Examples
' 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
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.