Command.AddControl 方法
更新:2007 年 11 月
创建此命令的持久性命令栏控件。
命名空间: EnvDTE
程序集: EnvDTE(在 EnvDTE.dll 中)
语法
声明
Function AddControl ( _
Owner As Object, _
Position As Integer _
) As CommandBarControl
用法
Dim instance As Command
Dim Owner As Object
Dim Position As Integer
Dim returnValue As CommandBarControl
returnValue = instance.AddControl(Owner, _
Position)
CommandBarControl AddControl(
Object Owner,
int Position
)
CommandBarControl^ AddControl(
[InAttribute] Object^ Owner,
[InAttribute] int Position
)
function AddControl(
Owner : Object,
Position : int
) : CommandBarControl
参数
Owner
类型:System.Object必选。要将新命令栏控件添加到的 Microsoft.VisualStudio.CommandBars.CommandBar 对象。
Position
类型:System.Int32可选。命令栏中放置新控件的索引位置,从 1 开始。
返回值
类型:Microsoft.Office.Core.CommandBarControl
Microsoft.VisualStudio.CommandBars.CommandBarControl 对象。
备注
环境保存该控件及其位置,并且不管是否已加载该外接程序,在环境的每个新会话期间,环境都会根据命令的 ContextUIGUIDs 或该控件对 QueryStatus Method 的响应,使该控件可用。
示例
' Macro code.
Imports Microsoft.Office.Core
Sub AddControlExample()
' Before running, you must add a reference to
' Microsoft.VisualStudio.CommandBars. 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.AddControl(cmdbarobj)
cmds.AddNamedCommand(colAddins.Item(1), "MyCommand", "Button Text", "Some tooltip", True)
End Sub
权限
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。