Commands2.AddCommandBar 方法 (String, vsCommandBarType, Object, Int32)

创建一个命令栏,该命令栏被保存并且在下次启动环境时可用。

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

参数

  • Position
    类型:System.Int32
    可选。命令栏中放置新命令栏的索引位置,从 1 开始。

返回值

类型:System.Object
CommandBar 对象。

备注

不管是否加载了外接程序,新命令栏在环境的每一个新会话期间都可用。

示例

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

请参见

参考

Commands2 接口

AddCommandBar 重载

EnvDTE80 命名空间