방법: 추가 기능을 도구 모음의 단추로 표시

업데이트: 2007년 11월

추가 기능 마법사를 사용하여 추가 기능을 만들 때 UI(사용자 인터페이스)를 만드는 옵션을 선택하면 도구 메뉴에 추가 기능을 위한 명령이 만들어집니다. 눈에 잘 띄거나 쉽게 액세스할 수 있는 위치(예: 기본 Visual Studio 도구 모음 또는 "표준" 도구 모음)에 추가 기능을 표시하려는 경우에도 이와 같이 합니다.

참고:

표시되는 대화 상자와 메뉴 명령은 실제 설정이나 버전에 따라 도움말에서 설명하는 것과 다를 수 있습니다. 이러한 절차는 일반 개발 설정을 사용하여 개발되었습니다. 설정을 변경하려면 도구 메뉴에서 설정 가져오기 및 내보내기를 선택합니다. 자세한 내용은 Visual Studio 설정을 참조하십시오.

절차

표준 도구 모음에 추가 기능을 표시하려면

  1. 추가 기능 프로젝트를 만들거나 엽니다.

  2. 추가 기능의 코드를 아래 코드로 바꿉니다.

예제

다음 예제에서는 Visual Studio "표준" 도구 모음에 단추를 추가하는 추가 기능을 만드는 방법을 보여 줍니다. 이는 Visual Studio에 있는 도구 모음의 이름입니다.

  1. AddNamedCommand2 메서드를 사용하여 추가 기능을 위한 명령을 만듭니다.

  2. 그런 다음 표준 도구 모음에 대한 참조를 가져옵니다.

  3. 마지막으로 AddControl 메서드를 사용하여 새 단추를 추가합니다.

Imports System
Imports Microsoft.VisualStudio.CommandBars
Imports Extensibility
Imports EnvDTE
Imports EnvDTE80

Public Class Connect

    Implements IDTExtensibility2
    Implements IDTCommandTarget

    Dim _applicationObject As DTE2
    Dim _addInInstance As AddIn
    Dim stdCmdBarCtl As CommandBarControl

    Public Sub New()

    End Sub

    Public Sub OnConnection(ByVal application As Object, ByVal _
      connectMode As ext_ConnectMode, ByVal addInInst As Object, _
      ByRef custom As Array) Implements IDTExtensibility2.OnConnection
        Dim cmd As Command
        Dim stdCmdBar As CommandBar
        Dim cmdBarBtn As CommandBarButton

        Try
            _applicationObject = CType(application, DTE2)
            _addInInstance = CType(addInInst, AddIn)

            Select Case connectMode
                Case ext_ConnectMode.ext_cm_AfterStartup, _
                  ext_ConnectMode.ext_cm_Startup
                    ' Add the command if it does not already exist.
                    If cmd Is Nothing Then
                        cmd = _applicationObject.Commands. _
                          AddNamedCommand(_addInInstance, _
                          "ANewCommand", "ANewCommand", _
                          "A new command", True, 59, Nothing, _
                          vsCommandStatus.vsCommandStatusSupported _
                          Or vsCommandStatus.vsCommandStatusEnabled)
                    End If

                    ' Reference the Visual Studio standard toolbar.
                    stdCmdBar =                 
                      CType(_applicationObject.CommandBars.Item _
                      ("Standard"), _
                      Microsoft.VisualStudio.CommandBars.CommandBar)

                    ' Add a button to the standard toolbar.
                    stdCmdBarCtl = CType(cmd.AddControl(stdCmdBar, _
                       stdCmdBar.Controls.Count + 1), _
                       Microsoft.VisualStudio.CommandBars. _
                       CommandBarControl)

                    ' Set a caption for the toolbar button.
                    stdCmdBarCtl.Caption = "A new command bar"

                    ' Set the toolbar's button style to an icon button.
                    cmdBarBtn = CType(stdCmdBarCtl, CommandBarButton)
                    cmdBarBtn.Style = MsoButtonStyle.msoButtonIcon
            End Select

        Catch e As System.Exception
            System.Windows.Forms.MessageBox.Show(e.ToString)
        End Try
    End Sub

    Public Sub OnDisconnection(ByVal disconnectMode As _
      ext_DisconnectMode, ByRef custom As Array) Implements  
      IDTExtensibility2.OnDisconnection
        Try
            ' When the add-in closes, get rid of the toolbar button.
            If Not (stdCmdBarCtl Is Nothing) Then
                stdCmdBarCtl.Delete()
            End If

        Catch e As System.Exception
            System.Windows.Forms.MessageBox.Show(e.ToString)
        End Try
    End Sub

    Public Sub OnAddInsUpdate(ByRef custom As Array) Implements _
      IDTExtensibility2.OnAddInsUpdate
    End Sub

    Public Sub OnStartupComplete(ByRef custom As Array) Implements _
      IDTExtensibility2.OnStartupComplete
    End Sub

    Public Sub OnBeginShutdown(ByRef custom As Array) Implements _
      IDTExtensibility2.OnBeginShutdown
    End Sub

    Public Sub QueryStatus(ByVal commandName As String, ByVal _
      neededText As vsCommandStatusTextWanted, ByRef status As _
      vsCommandStatus, ByRef commandText As Object) Implements _
      IDTCommandTarget.QueryStatus
        If neededText = EnvDTE.vsCommandStatusTextWanted. _
          vsCommandStatusTextWantedNone Then

            If commandName = "cmdBar2.Connect.ANewCommand" Then
                status = CType(vsCommandStatus.vsCommandStatusEnabled _
                  + vsCommandStatus.vsCommandStatusSupported, _
                  vsCommandStatus)
            Else
                status = vsCommandStatus.vsCommandStatusUnsupported
            End If
        End If
    End Sub

    Public Sub Exec(ByVal commandName As String, ByVal executeOption _
      As vsCommandExecOption, ByRef varIn As Object, ByRef varOut _
      As Object, ByRef handled As Boolean) Implements _
      IDTCommandTarget.Exec
        handled = False
        If executeOption = vsCommandExecOption. _
          vsCommandExecOptionDoDefault Then
            If commandName = "cmdBar2.Connect.ANewCommand" Then
                handled = True
                System.Windows.Forms.MessageBox.Show("Add-in running")
                Exit Sub
            End If
        End If
    End Sub
End Class

참고 항목

작업

방법: 추가 기능 관리자를 사용하여 추가 기능 제어

개념

도구 모음 및 메뉴에 추가 기능 표시

자동화 개체 모델 차트

참조

Visual Studio 명령 및 스위치

기타 리소스

추가 기능 및 마법사 만들기