次の方法で共有


ToolBoxItems.Add メソッド

新しいアイテムを作成し、[ツールボックス] に追加します。

名前空間:  EnvDTE
アセンブリ:  EnvDTE (EnvDTE.dll 内)

構文

'宣言
Function Add ( _
    Name As String, _
    Data As Object, _
    Format As vsToolBoxItemFormat _
) As ToolBoxItem
ToolBoxItem Add(
    string Name,
    Object Data,
    vsToolBoxItemFormat Format
)
ToolBoxItem^ Add(
    [InAttribute] String^ Name, 
    [InAttribute] Object^ Data, 
    [InAttribute] vsToolBoxItemFormat Format
)
abstract Add : 
        Name:string * 
        Data:Object * 
        Format:vsToolBoxItemFormat -> ToolBoxItem
function Add(
    Name : String, 
    Data : Object, 
    Format : vsToolBoxItemFormat
) : ToolBoxItem

パラメーター

  • Name
    型 : String

    必須。 新しいアイテムのキャプションを表す文字列。

  • Data
    型 : Object

    必須。 [ツールボックス] に追加される文字列、コントロール、またはその他のアイテムを表すバリアント。

戻り値

型 : EnvDTE.ToolBoxItem
ToolBoxItem オブジェクト。

解説

削除された ToolBoxTab オブジェクトに ToolBoxItems コレクションが属している場合、または既に存在する名前のタブを追加しようとした場合、このメソッドは失敗します。

Visual C++ を使用している場合は、Data 引数に IDataObject の IUnknown を渡すことができます。

Format が vsToolBoxItemFormatDotNETComponent のアセンブリを追加する場合は、Data パラメーターに以下のいずれかの形式の値を渡すことができます。

  • <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

.NET Framework セキュリティ

  • 直前の呼び出し元に対する完全な信頼。このメンバーは、部分的に信頼されているコードから使用することはできません。詳細については、「部分信頼コードからのライブラリの使用」を参照してください。

参照

関連項目

ToolBoxItems インターフェイス

EnvDTE 名前空間

その他の技術情報

方法 : ツールボックスを制御する