ToolBoxItems.Add メソッド
更新 : 2007 年 11 月
新しいアイテムを作成し、[ツールボックス] に追加します。
名前空間 : EnvDTE
アセンブリ : EnvDTE (EnvDTE.dll 内)
構文
'宣言
Function Add ( _
Name As String, _
Data As Object, _
Format As vsToolBoxItemFormat _
) As ToolBoxItem
'使用
Dim instance As ToolBoxItems
Dim Name As String
Dim Data As Object
Dim Format As vsToolBoxItemFormat
Dim returnValue As ToolBoxItem
returnValue = instance.Add(Name, Data, _
Format)
ToolBoxItem Add(
string Name,
Object Data,
vsToolBoxItemFormat Format
)
ToolBoxItem^ Add(
[InAttribute] String^ Name,
[InAttribute] Object^ Data,
[InAttribute] vsToolBoxItemFormat Format
)
function Add(
Name : String,
Data : Object,
Format : vsToolBoxItemFormat
) : ToolBoxItem
パラメータ
Name
型 : System.String必ず指定します。新しいアイテムのキャプションを表す文字列。
Data
型 : System.Object必ず指定します。[ツールボックス] に追加される文字列、コントロール、またはその他のアイテムを表すバリアント。
Format
型 : EnvDTE.vsToolBoxItemFormat省略可能です。新しいアイテムの形式を示す vsToolBoxItemFormat 定数。
戻り値
ToolBoxItem オブジェクト。
解説
削除された ToolBoxTab オブジェクトに ToolBoxItems コレクションが属している場合、または既に存在する名前のタブを追加しようとした場合、このメソッドは失敗します。
Visual C++ を使用している場合は、Data 引数に IDataObject の IUnknown を渡すことができます。
Format が vsToolBoxItemFormatDotNETComponent のアセンブリを追加する場合は、Name パラメータに以下のいずれかの形式の値を渡すことができます。
<AssemblyPath> : "<AssemblyPath>" は、管理されているアセンブリを指すパスおよびファイル名を指定します (例 : C:\Libraries\MyAssembly.dll)。この形式を使用すると、.DLL 内のすべてのクラスが [ツールボックス] に追加されます。
<AssemblyNameInTheGAC> : アセンブリで限定された参照としてリストされている単一のクラスを指定します。単一のクラスをコントロールとして追加できるのは、そのクラスがグローバル アセンブリ キャッシュ (GAC) にあるアセンブリへの参照である場合です (例 : WindowControlLibrary1.UserControl1, WindowControlLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=<Your Token>)。<Your Token> には公開キー トークンを指定します。公開キー トークンは、アセンブリを GAC に追加する際に必要です。
例
次に示すのは、テキスト ドキュメントを [ツールボックス] に追加する方法の例です。
Sub ToolBoxAddExample1()
' This adds a Text item to the first tab of the ToolBox.
' Define the variables and create an object reference to the IDE's
' ToolBox object.
Dim win As Window = DTE.Windows.Item(Constants.vsWindowKindToolbox)
Dim tlbox As ToolBox = win.Object
Dim tbxTabs As ToolBoxTabs
' Create an object reference to the ToolBoxTabs object.
tbxTabs = tlbox.ToolBoxTabs
' Add a new Text item to the first tab in the ToolBox.
tbxTabs.Item(1).ToolBoxItems.Add("New Text Item", "Some text to _
add to the document.", vsToolBoxItemFormat.vsToolBoxItemFormatText)
End Sub
次に示すのは、ファイルへのパスを使って .NET コンポーネントを [ツールボックス] に追加する方法の例です。追加するコンポーネントは、Visual Basic Windows コントロール ライブラリ コンポーネントなどの .NET コントロールである必要があります。
Sub ToolBoxItemAddExample2()
Try
Dim tlBox As ToolBox
tlBox = CType(DTE.Windows.Item(Constants. _
vsWindowKindToolbox).Object, EnvDTE.ToolBox)
' Create a new tab called "My Controls."
Dim tlBoxTab As ToolBoxTab = tlBox.ToolBoxTabs. _
Add("My Controls")
' Set focus to the new Toolbox tab.
tlBoxTab.Activate()
' Add a .NET control as a new control in the new ToolBox tab.
' The constant "vsToolBoxItemFormatDotNETComponent" alerts the
' ToolBox to the type of control you are adding.
tlBoxTab.ToolBoxItems.Add("MyDotNetControl", _
"C:\Libraries\ADotNetControl.dll(", _
vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent)
Catch ex As System.Exception
' Display any errors that occur.
MsgBox("ERROR: " & ex.Message)
End Try
End Sub
アクセス許可
- 直前の呼び出し元に対する完全な信頼。このメンバは、部分的に信頼されているコードから使用することはできません。詳細については、「部分信頼コードからのライブラリの使用」を参照してください。