Command.AddControl 方法

创建此命令的持久性命令栏控件。

命名空间:  EnvDTE
程序集:  EnvDTE(在 EnvDTE.dll 中)

语法

声明
Function AddControl ( _
    Owner As Object, _
    Position As Integer _
) As Object
Object AddControl(
    Object Owner,
    int Position
)
Object^ AddControl(
    [InAttribute] Object^ Owner, 
    [InAttribute] int Position
)
abstract AddControl : 
        Owner:Object * 
        Position:int -> Object
function AddControl(
    Owner : Object, 
    Position : int
) : Object

参数

  • Owner
    类型:Object

    必需。 要添加新命令栏控件的 CommandBar 对象。

  • Position
    类型:Int32

    可选。 命令栏中放置新控件的索引位置,从 1 开始。

返回值

类型:Object
CommandBarControl 对象。

备注

该环境保存控件及其位置,使其可用于根据指令的 ContextUIGUIDs,当提供不加载外接程序时,或者它对 QueryStatus Method "的响应,可在加载时。

示例

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

.NET Framework 安全性

请参阅

参考

Command 接口

EnvDTE 命名空间