Commands2.AddNamedCommand 方法

创建命名命令,该命令由环境保存,并且在下次环境启动时(无论是否加载外接程序)可用。

命名空间:  EnvDTE80
程序集:  EnvDTE80(在 EnvDTE80.dll 中)

语法

声明
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

参数

  • AddInInstance
    类型:AddIn

    必需。 添加新命令的 AddIn 对象。

  • Name
    类型:String

    必需。 新命令名称的缩写形式。 AddNamedCommand 在此内容前加上“Addins.Progid.”来创建唯一名称。

  • ButtonText
    类型:String

    必需。 在命令绑定到以名称而不是以图标显示的按钮时使用的名称。

  • Tooltip
    类型:String

    必需。 当用户将鼠标指针悬停在任何绑定到新命令的控件上时所显示的文本。

  • MSOButton
    类型:Boolean

    必需。 应始终 false。

  • Bitmap
    类型:Int32

    可选。 在按钮上显示的位图的 ID。

  • ContextUIGUIDs
    类型:array<Object[]%

    可选。 GUID 确定哪些环境上下文 (即调试模式,设计模式,等等) 显示命令

  • vsCommandDisabledFlagsValue
    类型:Int32

    可选。 确定当您提供了 ContextUIGUIDs 且指定上下文当前都不活动时此命令的状态。 此参数应始终包括 vsCommandStatusSupported。 如果此参数还包括 vsCommandStatusEnabled,则将启用命令。

返回值

类型:Command
Command 对象。

备注

外接程序以后可以通过响应 QueryStatus 方法来更改 ButtonText 名称。 如果文本以 # 开头,则该字符串的其余部分是一个整数,该整数表示外接程序已注册的附属 DLL 中的资源 ID。

外接程序未加载并因此无法响应 QueryStatus 方法时使用 ContextUIGUIDs 参数和 vsCommandStatusValue 参数。 如果 ContextUIGUIDs 为空,则在加载外接程序并可以响应 QueryStatus 之前,一直启用该命令。

外接程序可以通过 IDTCommandTarget 接口接收调用通知。 可以使用 IDTExtensibility2 接口的 OnConnection 方法来添加按钮。

示例

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 安全性

请参阅

参考

Commands2 接口

EnvDTE80 命名空间