次の方法で共有


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

Visual Studio アドインは、Visual Studio 2013 では使用されなくなりました。 アドインを VSPackage 拡張機能にアップグレードしてください。 アップグレードの詳細については、「FAQ: アドインを VSPackage 拡張に変換する」を参照してください。

ToolBox オブジェクトは、Visual Studio オートメーション モデルでは、次のオブジェクトおよびコレクションによって表されます。

オブジェクト名

説明

ToolBox オブジェクト

ツールボックスを表します。

ToolBoxTabs コレクション

ツールボックスにあるすべてのタブを表します。

ToolBoxTab2 オブジェクト

ツールボックスにある 1 つのタブを表します。

ToolBoxTab3 オブジェクト

ツールボックスにある 1 つのタブを表します。

ToolBoxItem2 コレクション

ツールボックスの 1 つのタブにあるすべての項目を含むコレクション。

ToolBoxItem オブジェクト

ツールボックスの 1 つのタブにある単一の項目を表します。

これらのオブジェクトとコレクションを使用して、次の操作を行うことができます。

  • ツールボックスにタブを追加します (Add メソッド)。

  • ツールボックス内のタブをアクティブにします (Activate メソッド)。

  • ツールボックスからタブを削除します (Delete メソッド)。

  • ツールボックスに項目を追加します (Add メソッド)。

  • ツールボックス内の項目を選択します (Select メソッド)。

  • ツールボックス内のタブから項目を削除します (Delete メソッド)。

  • ツールボックスの表示形式をアイコン ビューまたはリスト ビューに変更します (ListView プロパティ)。

ツールボックスの内容を制御するだけでなく、幅や高さなど、その特性も制御できます。 詳細については、「方法 : ウィンドウの特性を変更する」を参照してください。

注意

実際に画面に表示されるダイアログ ボックスとメニュー コマンドは、アクティブな設定またはエディションによっては、ヘルプの説明と異なる場合があります。ここに記載されている手順は、全般的な開発設定が適用されているものとして記述されています。設定を変更するには、[ツール] メニューの [設定のインポートとエクスポート] をクリックします。詳細については、「Visual Studio での開発設定のカスタマイズ」を参照してください。

使用例

次の例は、ツールボックス オートメーション モデルのさまざまなメンバーを参照および使用する方法を示しています。 この例では、ツールボックスの新しいタブを作成し、そのタブにいくつかの項目 (.NET コンポーネントなど) を追加した後、その項目のいずれかを削除します。 作成したタブを削除することもできます。 この例の実行方法の詳細については、「方法 : オートメーション オブジェクト モデルのコード例をコンパイルおよび実行する」を参照してください。

' VSMacro
Sub ToolboxExample()
    Dim tlBox As ToolBox
    Dim tbxTabs As ToolBoxTabs
    Dim tbxTab As ToolBoxTab
    Dim tbxItems As ToolBoxItems
    Dim tbxItem As ToolBoxItem

    Try
        ' Create an object reference to the IDE's ToolBox object and
        ' its tabs.
        tlBox = DTE.Windows.Item(Constants.vsWindowKindToolbox).Object
        tbxTabs = tlBox.ToolBoxTabs

        ' Add a new tab to the Toolbox and select it.
        tbxTab = tbxTabs.Add("New ToolBox Tab")
        tbxTab.Activate()

        ' Add new items to the new Toolbox tab. This shows two
        ' different ways to index the Toolbox tabs. The third item
        ' added is a .NET component that contains a number of 
        ' Web-related controls.
        tbxTab.ToolBoxItems.Add("Text Item", "Hello world")
        tbxTab.ToolBoxItems.Add("HTML Item", "Hello world", _
        vsToolBoxItemFormat.vsToolBoxItemFormatHTML)
        ' Replace the <Path and name of a .NET dll>
        ' with a path to a .NET dll file.
        tbxTabs.Item("New Toolbox Tab").ToolBoxItems.Add _
        ("DotNET Component", "< Path and name of a .NET dll >", _
 vsToolBoxItemFormat. _
        vsToolBoxItemFormatDotNETComponent)
        
        ' Use the ToolboxItems collection to access all the items under 
        ' a ToolBox tab.
        tbxItems = tbxTab.ToolBoxItems

        ' List the number of ToolboxItems in a ToolBoxTab.
        MsgBox _
("Number of items in " & tbxTabs.Item(1).Name & " tab: "  _
& tbxItems.Count)

        ' Select the second item in the ToolboxItems collection and 
        ' delete it.
        tbxItems.Item(2).Select()
        If (MsgBox("Delete the second ToolBox item?", vbYesNo) = vbYes) _
        Then
            tbxItems.SelectedItem.Delete()
            MsgBox("Number of items in " & tbxTabs.Item(1).Name & " _
            tab: " & tbxItems.Count)
        End If
        If (MsgBox("Delete the new tab?", vbYesNo) = vbYes) Then
            tbxTabs.Item("New ToolBox Tab").Delete()
            MsgBox("Tab deleted.")
        End If
    Catch ex As System.Exception
        MsgBox("ERROR: " & ex.Message)
    End Try
End Sub
Using System.Windows.Forms;
public void OnConnection(object application,
 Extensibility.ext_ConnectMode connectMode, object addInInst, ref
 System.Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;
    // Pass the applicationObject member variable to the code example.
    ToolboxExample(_applicationObject); 
}

public void ToolboxExample( DTE2 dte ) 
{ 
    ToolBox tlBox = null; 
    ToolBoxTabs tbxTabs = null; 
    ToolBoxTab3 tbxTab = null; 
    ToolBoxItems tbxItems = null; 
    ToolBoxItem2 tbxItem = null; 

    try 
    { 
        // Create an object reference to the IDE's ToolBox object and
        // its tabs.
        tlBox = (ToolBox )( dte.Windows.Item(
 Constants.vsWindowKindToolbox ).Object ); 
        tbxTabs = tlBox.ToolBoxTabs; 

        // Add a new tab to the Toolbox and select it.
        tbxTab = (ToolBoxTab3)tbxTabs.Add( "New ToolBox Tab" ); 
        tbxTab.Activate(); 

        // Add new items to the new Toolbox tab. This shows two
        // different ways to index the Toolbox tabs. The third item
        // added is a .NET component that contains a number of 
        // Web-related controls.
        tbxTab.ToolBoxItems.Add( "Text Item", "Hello world",
 (EnvDTE.vsToolBoxItemFormat.vsToolBoxItemFormatText)); 
        tbxTab.ToolBoxItems.Add( "HTML Item", "Hello world"
, vsToolBoxItemFormat.vsToolBoxItemFormatHTML ); 
        // Replace the <Path and name of a .NET dll>
        // with a path to a .NET dll file.
        tbxTabs.Item( "New Toolbox Tab" ).ToolBoxItems.Add
( "DotNET Component",
 "<Path and name of a .NET dll>",
 vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent ); 

        // Use the ToolboxItems collection to access all the 
        // items under a ToolBox tab.
        tbxItems = tbxTab.ToolBoxItems; 

        // List the number of ToolboxItems in a ToolBoxTab.
        MessageBox.Show( "Number of items in " +
 tbxTabs.Item( 1 ).Name + " tab: " + tbxItems.Count); 
          
        // Select the second item in the ToolboxItems collection and 
        // delete it.
        // Comment the following lines out, if you do not want to
        // delete the controls.
        tbxItems.Item( 2 ).Select(); 
        
        tbxItems.SelectedItem.Delete(); 
        MessageBox.Show( "Number of items in " 
+ tbxTabs.Item( 1 ).Name + " tab: " + tbxItems.Count); 
        tbxTabs.Item( "New ToolBox Tab" ).Delete(); 
        MessageBox.Show( "Tab deleted."); 
        
    } 
    catch ( System.Exception ex ) 
    { 
        MessageBox.Show( "ERROR: " + ex.Message); 
    } 
}

セキュリティ

登録の必要がある COM オブジェクトをツールボックスに追加すると、COM コンポーネントの登録が試行されます。 管理者 (Administrators グループのメンバー) としてログインしていない場合は登録に失敗し、COM オブジェクトはツールボックスに追加されません。

登録が解除された COM コンポーネントは、アクセス許可のレベルに関係なく、参照したりツールボックスに追加したりすることはできません。

参照

処理手順

方法 : ウィンドウの特性を変更する

方法 : アドインを作成する

チュートリアル : ウィザードの作成

概念

オートメーション オブジェクト モデルの階層図

その他の技術情報

環境ウィンドウの作成と制御

アドインおよびウィザードの作成

オートメーションと機能拡張のリファレンス