共用方式為


Command.AddControl 方法

建立命令的持續性 (Persistent) 命令列控制項。

命名空間:  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

參數

  • Position
    型別:System.Int32
    選擇項。在命令列中要放置新控制項的索引位置,從 1 開始。

傳回值

型別:System.Object
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

.NET Framework 安全性

請參閱

參考

Command 介面

EnvDTE 命名空間