次の方法で共有


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
    型 : System.Object
    必須。新しいコマンド バー コントロールの追加先である CommandBar オブジェクト。
  • 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 名前空間