Commands.AddNamedCommand 方法

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

命名空间:  EnvDTE
程序集:  EnvDTE(在 EnvDTE.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

参数

  • Name
    类型:String

    必选。 新命令名称的缩写形式。 AddNamedCommand 使用前缀 Addins.Progid. 来创建唯一名称。

  • ButtonText
    类型:String

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

  • Tooltip
    类型:String

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

  • MSOButton
    类型:Boolean

    必选。 指示指定命令的按钮图片是否是 Office 图片。 True = 按钮。 如果 MSOButton 为 False,则 Bitmap 为 Visual C++ 资源 DLL 中的 16x16 位图资源(而不是图标资源)的 ID,此资源 DLL 必须驻留在具有语言的区域设置标识符(简体中文为 2052)的文件夹中。

  • Bitmap
    类型:Int32

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

  • ContextUIGUIDs
    类型:array<Object[]%

    可选。 GUID 的 SafeArray,它确定哪些环境上下文(即调试模式、设计模式等)显示此命令。 请参见 vsCommandDisabledFlags

  • vsCommandDisabledFlagsValue
    类型:Int32

返回值

类型:EnvDTE.Command
一个 Command 对象。

备注

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

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

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

示例

' Macro code.
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 安全性

请参阅

参考

Commands 接口

EnvDTE 命名空间