共用方式為


Commands.AddCommandBar 方法

建立一個會儲存並且可在下次環境啟動時使用的命令列。

命名空間:  EnvDTE
組件:  EnvDTE (在 EnvDTE.dll 中)

語法

'宣告
Function AddCommandBar ( _
    Name As String, _
    Type As vsCommandBarType, _
    CommandBarParent As Object, _
    Position As Integer _
) As Object
Object AddCommandBar(
    string Name,
    vsCommandBarType Type,
    Object CommandBarParent,
    int Position
)
Object^ AddCommandBar(
    [InAttribute] String^ Name, 
    [InAttribute] vsCommandBarType Type, 
    [InAttribute] Object^ CommandBarParent, 
    [InAttribute] int Position
)
abstract AddCommandBar : 
        Name:string * 
        Type:vsCommandBarType * 
        CommandBarParent:Object * 
        Position:int -> Object
function AddCommandBar(
    Name : String, 
    Type : vsCommandBarType, 
    CommandBarParent : Object, 
    Position : int
) : Object

參數

  • Name
    類型:String

    必要項。 新命令列的名稱。

  • CommandBarParent
    類型:Object

    選擇項。 要加入新命令列的 Office CommandBar 物件 (但是,如果 Type 為 vsCommandBarTypeMenu,這將會是必要項)。

  • Position
    類型:Int32

    選擇項。 在命令列中要放置新命令列的索引位置,從一開始。

傳回值

類型:Object
CommandBar 物件。

備註

CommandBar 物件是 Microsoft Office 物件模型的成員。

透過此方法新增的指令列是永久的指令列,無論是否載入增益集,每個 IDE 工作階段皆可使用此指令列。 只有在您想要永久命令列時,才應該使用這個方法來加入命令列。 您只能在第一次載入增益集時呼叫這個方法一次。 如果您想要只會在實際載入增益集時出現的暫時指令列,必須在載入增益集時使用 DTE.CommandBars.Add方法,然後在卸載增益集時叫用DTE.CommandBars.Remove方法。

由於即使未載入增益集,也會出現永久命令列,解除安裝增益集時,您一定要移除該命令列。 因此,必須使用 MSI 來安裝和解除安裝增益集,並將自訂動作加入至您的解除安裝程式。

如需新增和移除永久和臨時命令列的詳細資訊,請參閱HOWTO: 從增益集將按鈕、命令列和工具列新增至 Visual StudioHOWTO: 在解除安裝 Visual Studio .NET 增益集時移除指令和 UI 項目

範例

' Macro code.
Imports Microsoft.VisualStudio.CommandBars
Sub AddCommandBarExample()
   ' 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 customin, customout As Object
   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.
   cmdbarobj = cmds.AddCommandBar("Mycmdbar", _
   vsCommandBarType.vsCommandBarTypeToolbar)
   MsgBox("Commandbar name: " & cmdbarobj.Name)
   cmdobj = cmds.AddNamedCommand(colAddins.Item(1), "mycommand", _
   "mycommand", "tooltip for mycommand", True)
End Sub

.NET Framework 安全性

請參閱

參考

Commands 介面

EnvDTE 命名空間