Commands2.AddNamedCommand Method

Creates a named command that is saved by the environment and made available the next time the environment starts, even if the Add-in is not loaded on environment startup.

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

Syntax

'Declaration
Function AddNamedCommand ( _
    AddInInstance As AddIn, _
    Name As String, _
    ButtonText As String, _
    Tooltip As String, _
    MSOButton As Boolean, _
    Bitmap As Integer, _
    ByRef ContextUIGUIDs As Object(), _
    vsCommandDisabledFlagsValue As Integer _
) As Command
Command AddNamedCommand(
    AddIn AddInInstance,
    string Name,
    string ButtonText,
    string Tooltip,
    bool MSOButton,
    int Bitmap,
    ref Object[] ContextUIGUIDs,
    int vsCommandDisabledFlagsValue
)
Command^ AddNamedCommand(
    [InAttribute] AddIn^ AddInInstance, 
    [InAttribute] String^ Name, 
    [InAttribute] String^ ButtonText, 
    [InAttribute] String^ Tooltip, 
    [InAttribute] bool MSOButton, 
    [InAttribute] int Bitmap, 
    [InAttribute] array<Object^>^% ContextUIGUIDs, 
    [InAttribute] int vsCommandDisabledFlagsValue
)
abstract AddNamedCommand : 
        AddInInstance:AddIn * 
        Name:string * 
        ButtonText:string * 
        Tooltip:string * 
        MSOButton:bool * 
        Bitmap:int * 
        ContextUIGUIDs:Object[] byref * 
        vsCommandDisabledFlagsValue:int -> Command
function AddNamedCommand(
    AddInInstance : AddIn, 
    Name : String, 
    ButtonText : String, 
    Tooltip : String, 
    MSOButton : boolean, 
    Bitmap : int, 
    ContextUIGUIDs : Object[], 
    vsCommandDisabledFlagsValue : int
) : Command

Parameters

  • AddInInstance
    Type: EnvDTE.AddIn

    Required. The AddIn object that is adding the new command.

  • Name
    Type: String

    Required. The short form of the name for your new command. AddNamedCommand prefaces this with "Addins.Progid." to create a unique name.

  • ButtonText
    Type: String

    Required. The name to use if the command is bound to a button that is displayed by name rather than by icon.

  • Tooltip
    Type: String

    Required. The text displayed when a user hovers the mouse pointer over any control bound to the new command.

  • MSOButton
    Type: Boolean

    Required. Should always be false.

  • Bitmap
    Type: Int32

    Optional. The ID of a bitmap to display on the button.

  • ContextUIGUIDs
    Type: array<Object[]%

    Optional. The GUIDs that determine which environment contexts (that is, debug mode, design mode, and so on) show the command

  • vsCommandDisabledFlagsValue
    Type: Int32

    Optional. Determines the state of the command when you supply a ContextUIGUIDs and none of the specified contexts are currently active. This parameter should always include vsCommandStatusSupported. If it also includes vsCommandStatusEnabled, the command will be enabled.

Return Value

Type: EnvDTE.Command
A Command object.

Remarks

Add-ins can later change the ButtonText name by responding to the QueryStatus method. If the text begins with #, then the rest of the string is an integer that represents a resource ID in the Add-in's registered satellite DLL.

The ContextUIGUIDs parameter and the vsCommandStatusValue parameter are used when the addin is not loaded and thus cannot respond to the QueryStatus method. If ContextUIGUIDs is empty, then the command is enabled until the addin is loaded and can respond to QueryStatus.

The addin can receive invocation notification through the IDTCommandTarget interface. A button can be added by using the OnConnection method of the IDTExtensibility2 interface.

Examples

Imports Microsoft.VisualStudio.CommandBars
Sub AddControlExample()
   ' Before running, you must add a reference to the Office 
   ' typelib to gain access to the CommandBar object. 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 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.
   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

See Also

Reference

Commands2 Interface

EnvDTE80 Namespace