Freigeben über


Toggle Design and Source Windows Macro

This one comes from Austin out of our mailbag.  Thanks - Josh


I got tired of using the F7, Shift-F7 key shortcuts for toggling the Design and Source code windows.  So I wrote this little macro.

It works a little differently for ASP.NET files.  When toggling to the Design window the macro will open either in Design or HTML mode depending on the users setting.  Maybe someone else will find this macro usefull.

Imports EnvDTE

Imports System.Diagnostics

Imports System.ComponentModel.Design

Public Module ToggleWindows

Sub ToggleDesignAndCodeWindows()

If (((TypeOf DTE.ActiveWindow.Object Is IDesignerHost) OrElse (TypeOf DTE.ActiveWindow.Object Is HTMLWindow)) AndAlso (DTE.Commands.Item("View.ViewCode").IsAvailable)) Then

DTE.ExecuteCommand("View.ViewCode")

Else

Dim projItem As ProjectItem

Dim activeDocFullName As String = DTE.ActiveDocument.FullName

Dim formFullName As String = activeDocFullName.Substring(0, activeDocFullName.LastIndexOf("."))

projItem = DTE.Solution.FindProjectItem(formFullName)

If (Not projItem Is Nothing) Then

Try

projItem.Open(Constants.vsViewKindPrimary).Activate()

Catch e As System.NullReferenceException

' Do nothing. Needed for asmx and ascx pages.

End Try

Else

If DTE.Commands.Item("View.ViewDesigner").IsAvailable Then

DTE.ExecuteCommand("View.ViewDesigner")

Else

Beep()

End If

End If

End If

End Sub

End Module


 Check out these instructions for more information on using macros in the ide. 

Comments

  • Anonymous
    July 22, 2004
    I stumbled across this keyboard shortcut a few weeks ago, but have you tried Ctrl-PgUp and Ctrl-PgDn to toggle between Design and HTML modes??