Commands2.AddNamedCommand2 方法

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

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

语法

声明
Function AddNamedCommand2 ( _
    AddInInstance As AddIn, _
    Name As String, _
    ButtonText As String, _
    Tooltip As String, _
    MSOButton As Boolean, _
    Bitmap As Object, _
    ByRef ContextUIGUIDs As Object(), _
    vsCommandStatusValue As Integer, _
    CommandStyleFlags As Integer, _
    ControlType As vsCommandControlType _
) As Command
Command AddNamedCommand2(
    AddIn AddInInstance,
    string Name,
    string ButtonText,
    string Tooltip,
    bool MSOButton,
    Object Bitmap,
    ref Object[] ContextUIGUIDs,
    int vsCommandStatusValue,
    int CommandStyleFlags,
    vsCommandControlType ControlType
)
Command^ AddNamedCommand2(
    [InAttribute] AddIn^ AddInInstance, 
    [InAttribute] String^ Name, 
    [InAttribute] String^ ButtonText, 
    [InAttribute] String^ Tooltip, 
    [InAttribute] bool MSOButton, 
    [InAttribute] Object^ Bitmap, 
    [InAttribute] array<Object^>^% ContextUIGUIDs, 
    [InAttribute] int vsCommandStatusValue, 
    [InAttribute] int CommandStyleFlags, 
    [InAttribute] vsCommandControlType ControlType
)
abstract AddNamedCommand2 : 
        AddInInstance:AddIn * 
        Name:string * 
        ButtonText:string * 
        Tooltip:string * 
        MSOButton:bool * 
        Bitmap:Object * 
        ContextUIGUIDs:Object[] byref * 
        vsCommandStatusValue:int * 
        CommandStyleFlags:int * 
        ControlType:vsCommandControlType -> Command 
function AddNamedCommand2(
    AddInInstance : AddIn, 
    Name : String, 
    ButtonText : String, 
    Tooltip : String, 
    MSOButton : boolean, 
    Bitmap : Object, 
    ContextUIGUIDs : Object[], 
    vsCommandStatusValue : int, 
    CommandStyleFlags : int, 
    ControlType : vsCommandControlType
) : Command

参数

  • Name
    类型:System.String
    必选。新命令名称的缩写形式。AddNamedCommand2 使用前缀**Addins.Progid.**来创建一个唯一名称.
  • ButtonText
    类型:System.String
    必选。在命令绑定到以名称而不是以图标显示的按钮时使用的名称。
  • Tooltip
    类型:System.String
    必选。当用户将鼠标指针悬停在任何绑定到新命令的控件上时所显示的文本。
  • MSOButton
    类型:System.Boolean
    必选。指示如何解释位图参数。
    如果值为 true,则 Bitmap 为 Microsoft Office 位图的 ID。
    如果 MSOButton 为 false,则 Bitmap 可能为以下之一:
    - 一个 Bitmap
    - 一个 Icon
    - 一个 IPicture
    - 由外接程序提供的 16x16 位图资源(但不是图标资源)的 ID。Visual Studio 将首先在外接程序的附属 DLL 中进行查找。如果没有找到资源,则将搜索加载程序 DLL。
  • Bitmap
    类型:System.Object
    可选。在按钮上显示的位图的 ID。请参见MSOButton。
  • ContextUIGUIDs
    类型:array<System.Object[]%
    可选。GUID 的 SafeArray,它确定哪些环境上下文(即调试模式、设计模式等)显示此命令。请参见 vsCommandDisabledFlags
  • vsCommandStatusValue
    类型:System.Int32
    可选。确定当您提供了 ContextUIGUIDs 而当前它们都不活动时,此命令的禁用状态是不可见还是灰色的。

返回值

类型:EnvDTE.Command
已创建的命名命令。

备注

有关如何获取 MSO 按钮的位图 ID 值的信息,请参见在 Microsoft Office 系统的命令栏中罗列按钮表面

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

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

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

.NET Framework 安全性

请参见

参考

Commands2 接口

EnvDTE80 命名空间