建立鍵盤快速鍵速查表。
大部分開發人員都不瞭解這一點,但實際上,Visual Studio 預設提供了 450 多個鍵盤快速鍵。不過,對於如何找到 Visual Studio 內部的所有鍵盤快速鍵還沒有簡便的方法。您可以編寫一個簡單的宏,對於所有預設鍵盤快速鍵進行遍曆,找到它們所對應的操作。以下內容(列表 1)列出了這個宏的代碼。
Public Module Module1
Public Sub ListShortcutsInHTML()
'Declare a StreamWriter
Dim sw As System.IO.StreamWriter
sw = New System.IO.StreamWriter("c:\\Shortcuts.html", True, System.Text.Encoding.GetEncoding("SHIFT-JIS"))
'Write the beginning HTML
WriteHTMLStart(sw)
' Add a row for each keyboard shortcut
For Each c As EnvDTE.Command In DTE.Commands
If c.Name <> "" Then
Dim bindings As System.Array
bindings = CType(c.Bindings, System.Array)
For i As Integer = 0 To bindings.Length - 1
sw.WriteLine("<tr>")
sw.WriteLine("<td>" + c.Name + "</td>")
sw.WriteLine("<td>" + bindings(i) + "</td>")
sw.WriteLine("</tr>")
Next
End If
Next
'Write the end HTML
WriteHTMLEnd(sw)
'Flush and close the stream
sw.Flush()
sw.Close()
End Sub
Public Sub WriteHTMLStart(ByVal sw As System.IO.StreamWriter)
sw.WriteLine("<html>")
sw.WriteLine("<head>")
sw.WriteLine("<title>")
sw.WriteLine("Visual Studio Keyboard Shortcuts")
sw.WriteLine("</title>")
sw.WriteLine("</head>")
sw.WriteLine("<body>")
sw.WriteLine("<h1>Visual Studio 2005 Keyboard Shortcuts</h1>")
sw.WriteLine("<font size=""2"" face=""Verdana"">")
sw.WriteLine("<table border=""1"">")
sw.WriteLine("<tr BGCOLOR=""#018FFF""><td align=""center""><b>Command</b></td><td align=""center""><b>Shortcut</b></td></tr>")
End Sub
Public Sub WriteHTMLEnd(ByVal sw As System.IO.StreamWriter)
sw.WriteLine("</table>")
sw.WriteLine("</font>")
sw.WriteLine("</body>")
sw.WriteLine("</html>")
End Sub
End Module
列表 1. 在 HTML 檔案中產生鍵盤快速鍵的宏
要使用這個宏,請轉到“工具”,選擇“宏”,然後選擇“宏 IDE. . .”啟動“宏 IDE”。展開 MyMacros 工程,MyMacros 命名空間,然後雙擊“Module1”。將列表 1 中的內容複寫到“宏 IDE”然後運行宏即可。運行宏之後,將會產生 Visual Studio 的鍵盤快速鍵參考資訊。開啟包含輸出內容的 C:\demo\Shortcuts.html 檔案。“圖 1”顯示了部分輸出內容。如果方便就將它列印出來,貼在電腦附近,以便學習新的鍵盤快速鍵。