Command.AddControl 方法
更新:2007 年 11 月
建立命令的持續性 (Persistent) 命令列控制項。
命名空間: 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
使用權限
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。