在标记和代码之间切换的快捷方式
时间:2020-03-06 14:35:14 来源:igfitidea点击:
使用Visual Studio 2008 Team Edition,是否可以分配在标记和代码之间切换的快捷键?如果没有,是否可以分配从代码到标记的快捷键?
解决方案
以下是Lozza在http://www.codinghorror.com/blog/archives/000315.html上的评论中的宏。我们只需要将其绑定到我们选择的快捷方式即可:
Sub SwitchToMarkup()
Dim FileName
If (DTE.ActiveWindow.Caption().EndsWith(".cs")) Then
' swith from .aspx.cs to .aspx
FileName = DTE.ActiveWindow.Document.FullName.Replace(".cs", "")
If System.IO.File.Exists(FileName) Then
DTE.ItemOperations.OpenFile(FileName)
End If
ElseIf (DTE.ActiveWindow.Caption().EndsWith(".aspx")) Then
' swith from .aspx to .aspx.cs
FileName = DTE.ActiveWindow.Document.FullName.Replace(".aspx", ".aspx.cs")
If System.IO.File.Exists(FileName) Then
DTE.ItemOperations.OpenFile(FileName)
End If
ElseIf (DTE.ActiveWindow.Caption().EndsWith(".ascx")) Then
FileName = DTE.ActiveWindow.Document.FullName.Replace(".ascx", ".ascx.cs")
If System.IO.File.Exists(FileName) Then
DTE.ItemOperations.OpenFile(FileName)
End If
End If
End Sub
不知道这是否是意思,因为我自己不进行ASPX开发,但是F7(显示代码)和Shift-F7(显示设计器)的默认键绑定不在代码和设计之间切换吗?它们在我的VS2008中(在WinForms可设计项目上)与我使用的默认Ckey绑定相同。

