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
アクセス許可
- 直前の呼び出し元に対する完全な信頼。このメンバは、部分的に信頼されているコードから使用することはできません。詳細については、「部分信頼コードからのライブラリの使用」を参照してください。