Share via


방법: 도구 상자 제어

업데이트: 2007년 11월

ToolBox 개체는 Visual Studio 자동화 모델에서 다음 개체 및 컬렉션으로 나타납니다.

개체 이름

설명

ToolBox 개체

도구 상자를 나타냅니다.

ToolBoxTabs 컬렉션

도구 상자에 있는 모든 탭을 나타냅니다.

ToolBoxTab2 개체

도구 상자의 단일 탭을 나타냅니다.

ToolBoxItem2 컬렉션

도구 상자 탭의 모든 항목을 포함하는 컬렉션입니다.

ToolBoxItem 개체

도구 상자 탭의 단일 항목을 나타냅니다.

이러한 개체 및 컬렉션을 사용하여 다음 작업을 수행할 수 있습니다.

  • 도구 상자에 탭 추가(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; 
    ToolBoxTab2 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 = (ToolBoxTab2)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 구성 요소는 사용자의 권한 수준에 관계없이 도구 상자에 추가할 수 없고 탐색할 수도 없습니다.

참고 항목

작업

방법: 창 특성 변경

방법: 추가 기능 만들기

연습: 마법사 만들기

개념

자동화 개체 모델 차트

기타 리소스

환경 창 만들기 및 제어

추가 기능 및 마법사 만들기

자동화 및 확장성 참조