Click to Rate and Give Feedback
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
Visual Studio Automation and Extensibility Reference
Command.AddControl Method

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
Visual Basic (Usage)
Dim instance As Command
Dim Owner As Object
Dim Position As Integer
Dim returnValue As Object

returnValue = instance.AddControl(Owner, Position)
C#
Object AddControl (
    [InAttribute] Object Owner,
    [OptionalAttribute] [InAttribute] int Position
)
C++
Object^ AddControl (
    [InAttribute] Object^ Owner, 
    [InAttribute] [OptionalAttribute] int Position
)
J#
Object AddControl (
    /** @attribute InAttribute() */ Object Owner, 
    /** @attribute InAttribute() */ /** @attribute OptionalAttribute() */ int Position
)
JScript
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.

Visual Basic
' 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
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker