Share via


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
    형식: System.String
    필수적 요소로서,새 항목의 캡션을 나타내는 문자열입니다.
  • Data
    형식: System.Object
    필수적 요소로서,도구 상자에 추가할 문자열, 컨트롤 또는 기타 항목을 나타내는 variant입니다.

반환 값

형식: 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 구성 요소를 도구 상자에 추가하는 방법을 보여 줍니다. 추가할 구성 요소는 .NET 컨트롤이어야 합니다(예: Visual Basic Windows 컨트롤 라이브러리 구성 요소).

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 네임스페이스

기타 리소스

방법: 도구 상자 제어