共用方式為


如何:檢視現有的金鑰繫結

.Visual Studio 增益集在 Visual Studio 2013 中已不適用。 您應該升級您的增益集至 VSPackage 擴展套件。 如需升級的詳細資訊,請參閱 常見問題集:將增益集轉換成 VSPackage 擴充功能

Bindings 屬性可以讓您檢視或變更與指定命令有關聯的按鍵繫結。 讀取此屬性會以物件陣列的形式擷取命令目前的繫結。 每個物件都包含描述繫結的字串。

如果將值設定為 Bindings 屬性,會為指定的命令指定一個或多個新的按鍵繫結。 如需詳細資訊,請參閱如何:繫結命令至單一快速鍵如何:將一個命令繫結至多個鍵盤快速鍵

注意事項注意事項

根據您目前使用的設定或版本,您所看到的對話方塊與功能表指令可能會與 [說明] 中描述的不同。使用 [一般開發設定] 開發了這些程序。若要變更設定,請從 [工具] 功能表中選擇 [匯入和匯出設定]。如需詳細資訊,請參閱Visual Studio 中的自訂開發設定

檢視現有的按鍵繫結

  1. 建立增益集。

    如需使用 [Visual Studio 增益集精靈] 的詳細資訊,請參閱 如何:建立增益集

  2. 加入 System.Windows.Forms 的參考,並將這個命名空間加入至 Connect 類別的 using (或 Imports) 陳述式。

  3. 將下列函式貼到程式碼的 Connect 類別。

  4. 若要執行增益集,請按一下 [工具] 功能表上的 [增益集管理員]、選取您建立的增益集,然後按一下 [確定]。

    訊息方塊顯示所有繫結至 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);
}

請參閱

工作

如何:保留現有的鍵盤快速鍵

概念

繫結屬性參數格式

其他資源

繫結增益集命令至按鍵