방법: 기존 키 바인딩 보기

Bindings 속성을 사용하면 지정된 명령과 연결되어 있는 키 바인딩을 보거나 변경할 수 있습니다.이 속성을 읽으면 명령의 현재 바인딩을 개체 배열로 가져올 수 있습니다.각 개체에는 바인딩을 설명하는 문자열이 들어 있습니다.

Bindings 속성에 대한 값을 설정하면 지정된 명령에 하나 이상의 새로운 키 바인딩이 할당됩니다.자세한 내용은 방법: 단일 바로 가기 키에 명령 바인딩명령: 명령을 여러 바로 가기 키에 바인딩을 참조하십시오.

[!참고]

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

기존의 키 바인딩 보기

  1. Visual Studio 추가 기능 마법사를 사용하여 새 추가 기능을 만듭니다.프로젝트의 이름을 지정하고 확인을 클릭하여 마법사를 시작합니다.

    Visual Studio 추가 기능 마법사를 사용하는 방법에 대한 자세한 내용은 방법: 추가 기능 만들기를 참조하십시오.

  2. 프로그래밍 언어 선택 페이지에서 Visual C#을 사용하여 추가 기능 만들기를 선택하여 아래의 Visual C# 예제를 실행하거나, Visual Basic을 사용하여 추가 기능 만들기를 선택하여 Visual Basic 예제를 실행합니다.

  3. 아래의 예제 함수를 Visual Studio 추가 기능 마법사로 생성한 코드의 Connect 클래스에 붙여넣습니다.

  4. 방법: 자동화 개체 모델 코드의 예제 컴파일 및 실행의 설명에 따라 OnConnection 메서드에서 함수를 호출합니다.

  5. 추가 기능을 실행하려면 도구 메뉴에서 추가 기능 관리자를 클릭하고 방금 만든 추가 기능을 선택한 다음 확인을 클릭합니다.

    File.NewFile 명령에 바인딩된 바로 가기 키의 전체 목록이 나타납니다.

예제

다음 예제에서는 File.NewFile 명령에 바인딩된 모든 바로 가기 키를 표시하여 Bindings를 사용하는 방법을 보여 줍니다.

Public Sub OnConnection(ByVal application As Object, ByVal _
  connectMode As ext_ConnectMode, ByVal addInInst As Object, ByRef _
  custom As Array) Implements IDTExtensibility2.OnConnection
    _applicationObject = CType(application, DTE2)
    _addInInstance = CType(addInInst, AddIn)
    ' Pass the applicationObject member variable to the code example.
    ListKeyBindings(_applicationObject)
End Sub

Sub ListKeyBindings(ByVal dte As DTE2)
    ' Bindings() is an array of key binding string names.
    Dim bindings() As Object
    Dim binding As Object
    Dim msg As String = Nothing
    ' Populate the collection with all of the bindings
    ' for the command File.NewFile.
    bindings = dte.Commands.Item("File.NewFile").Bindings
    For Each binding In bindings
        msg += CStr(binding) & vbCr
    Next
    MsgBox(msg)
 End Sub
// Add-in code.
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.
    ListKeyBindings((DTE2)_applicationObject);
}
public void ListKeyBindings(DTE2 dte)
{
    object[] bindings;
    string msg = string.Empty;
    // Populate the collection with all of the bindings associated
    // with the command File.NewFile.
    // Bindings() is an array of key binding string names.
    bindings = (object[])dte.Commands.Item("File.NewFile", 0).Bindings;
    foreach (object b in bindings)
    {
        msg += ((string)b) + "\n";
    }
    System.Windows.Forms.MessageBox.Show(msg);
}

참고 항목

작업

방법: 기존 바로 가기 키 유지

개념

Bindings 속성 매개 변수 형식

기타 리소스

추가 기능 명령을 키에 바인딩