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
    - 增益集所提供之 16 x 16 點陣圖資源 (不是圖示資源) 的識別碼。Visual Studio 將會先在增益集的附屬 DLL 中尋找。如果在其中沒有找到資源,將搜尋增益集 DLL。
  • Bitmap
    型別:System.Object
    選擇項。要顯示在按鈕上之點陣圖的 ID。請參閱MSOButton。
  • ContextUIGUIDs
    型別:array<System.Object[]%
    選擇項。GUID 的 SafeArray,可以判斷何種環境內容 (即偵錯模式和設計模式等等) 會顯示這個命令。請參閱 vsCommandDisabledFlags
  • vsCommandStatusValue
    型別:System.Int32
    選擇項。在您提供 ContextUIGUIDs 但目前都不是現用中時,判斷命令的停用狀態是不可見還是灰色的。
  • CommandStyleFlags
    型別:System.Int32
    選擇項。在您提供 ContextUIGUIDs 但所有指定的內容目前都不是作用中狀態時,判斷命令的狀態。這個參數一定要包含 vsCommandStatusSupported。如果該參數還包含 vsCommandStatusEnabled,則會啟用該命令。

傳回值

型別:EnvDTE.Command
已建立的具名命令。

備註

如需如何取得 MSO 按鈕之點陣圖 ID 值的詳細資訊,請參閱在 Microsoft Office System 的命令列中列出按鈕表面 (英文)。

增益集可以稍後藉由回應 QueryStatus 方法來變更 ButtonText 名稱。 如果文字是以 "#" 開頭,那麼字串的其餘部分就是一個整數,代表在增益集已註冊附屬 DLL (Satellite DLL) 中的資源 ID。

ContextUIGUIDs 參數和 vsCommandStatusValue 參數用於未載入增益集的時候,因此無法回應 QueryStatus方法。 如果 ContextUIGUIDs 是空的,那麼該命令會一直啟用,直到載入增益集並能回應 QueryStatus 為止。

增益集可以透過 IDTCommandTarget 介面接收引動過程告知。 使用 IDTExtensibility2 介面的 OnConnection 方法即可加入按鈕。

.NET Framework 安全性

請參閱

參考

Commands2 介面

EnvDTE80 命名空間