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
参数
- Name
类型:System.String
必选。新命令栏的名称。
- Type
类型:EnvDTE.vsCommandBarType
必选。用于确定命令栏类型的 vsCommandBarType 常数:
- CommandBarParent
类型:System.Object
可选。要添加新命令栏的 CommandBar 对象。(但是,如果 Type 是 vsCommandBarTypeMenu,则该项为必选项。)
- 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 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。