Click here to Skip to main content
14,447,134 members

Visual Studio .NET Shortcuts for Toggling Tool Windows

Rate this:
4.55 (7 votes)
Please Sign up or sign in to vote.
4.55 (7 votes)
14 May 2002CPOL
Activate common tool windows without using the mouse


When working in the Developer Studio IDE for Visual C++ 4, 5 and 6 I got used to the convenience of being able to toggle the Workspace and Output windows between "open" and "closed" states with the click of a button. The Workspace window in Developer Studio contained, as window tabs, File View, Class View and Resource View. These are windows in their own right in the Visual Studio .NET IDE. (Solution Explorer is the equivalent of Developer Studio's File View.) In Developer Studio the buttons for toggling the Workspace and Output windows were available on the toolbar. I also used to assign the commands to keyboard shortcuts, e.g.,

Alt+X,W = View.ToggleWorkspaceWindow
Alt+X,O = View.ToggleOutputWindow

I found this more convenient than having to use the menu and the mouse. 

In the new Microsoft Development Environment for Visual Studio .NET, which contains a lot more windows (called Tool Windows), it would be nice to be able to do something similar. I find that for C# and Visual Basic I frequently access the following Tool Windows:

  • Solution Explorer
  • Class View
  • Toolbox
  • Properties
  • Macro Explorer

Often I'll want to access a window and perform an operation, such as set a property or select a control or navigate to a method, and then write some code. When I'm writing code I will often want access to the full width of the screen. The Auto Hide feature of the IDE is great for this. However, sometimes I want to be able to activate a particular tool window without using the mouse and I may want to disable Auto Hide for a while and then close the tool window again without using the mouse. You can do this with a combination of macros and command aliases.

Activating a Tool Window

To do this using the keyboard you can of course use the "Alt" keyboard shortcuts for accessing the menu commands or memorise a predefined assigned keyboard shortcut if one exists. For example, to view Solution Explorer:

Alt+V, P or Ctrl+Alt+L

However, these aren't, in general, easy to remember. This is where command aliases come in handy. See the topic, Creating Custom Aliases for Visual Studio Commands, in the Visual Studio online help. A command alias is a custom name for an IDE command.

Here's how to define a command alias.

Open the command window (View->Other Windows->Command Window).

At the > prompt type alias, then the name for the alias, followed by the command you want to create an alias for. For example:

alias vs View.SolutionExplorer

If you now type vs at the > prompt the IDE command, View.SolutionExplorer, is executed and the Solution Explorer window will appear activated. 

This can be made more convenient because command aliases can also be created and executed in the Find text box on the toolbar (referred to as the Find/Command box in the online help). If you type > in the Find/Command box it switches to command mode. For example, if you enter >vs the above alias will be executed. You can also explicitly enter >View.SolutionExplorer or any other IDE command and it will be executed. Intellisense auto-completion is also available. 

As an added convenience you can quickly enter command mode by typing Ctrl + /. So the quickest way to execute the alias we've defined for activating the Solution Explorer window is:

Ctrl + / followed by vs.

Hiding (Closing) a Tool Window

This is a bit more elaborate. There is probably a better way of doing this but this is the method I've adopted, which is good enough for now. First, activate the window:


Then close it:


As far as I can see you can't combine these into a single alias (but please correct me if I'm wrong) so, instead, we can define a VB macro that combines them. Then we can define an alias that executes the macro.

Here is the macro

Sub CloseSolutionExplorer()
End Sub

To create a Macro, select View->Other Windows->Macro Explorer. Select, say, the MyMacros project and then add a new module. Then write a Sub procedure as above.

An alias would look like this:    

alias hs Macros.MyMacros.General.CloseSolutionExplorer

where MyMacros is the project name and General is the module name.

So to close Solution Explorer type:

Ctrl + / followed by hs

I have repeated this exercise for the Class View, Properties, Tool Box and Macro Explorer windows and the results are shown below.

Summary of Shortcuts

Command Aliases

alias vc View.ClassView
alias vm View.MacroExplorer
alias vp View.PropertiesWindow
alias vs View.SolutionExplorer
alias vt View.Toolbox
alias hc Macros.MyMacros.General.CloseClassView
alias hm Macros.MyMacros.General.CloseMacroExplorer
alias hp Macros.MyMacros.General.ClosePropertiesWindow
alias hs Macros.MyMacros.General.CloseSolutionExplorer
alias ht Macros.MyMacros.General.CloseToolbox


Sub CloseClassView()
End Sub

Sub CloseToolbox()
End Sub

Sub CloseMacroExplorer()
End Sub

Sub ClosePropertiesWindow()
End Sub

Sub CloseSolutionExplorer()
End Sub

Note: The "Hide (Close) Window" aliases should not be called if the window is in Auto Hide mode, otherwise you will get an error message saying Command "Window.CloseToolWindow" is not available. This is innocuous though. If you want to suppress the error message you can modify the macro along the following lines:

Sub CloseSolutionExplorer()
  Catch ex As System.Runtime.InteropServices.COMException
  Catch ex As System.Exception
    MsgBox(ex.GetType().ToString() & vbNewLine & vbNewLine & ex.Message)
  End Try
End Sub

The error that the macro generates is a System.Runtime.InteropServices.COMException. So, catching it and doing nothing will suppress the dialog.

Outstanding Issues

Ideally, it would be nice if we could have a single command that operates as a toggle rather than having to have paired aliases, such as vs and hs. However, I have not been able to figure out how to do this in the Visual Studio Automation model.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Kevin McFarlane
Web Developer
United Kingdom United Kingdom
No Biography provided

Comments and Discussions

GeneralSimilar Code to Switch Between Multiple Layouts Pin
KRowe3-Oct-09 9:33
MemberKRowe3-Oct-09 9:33 
GeneralRe: Similar Code to Switch Between Multiple Layouts Pin
KLininger15-May-12 10:34
MemberKLininger15-May-12 10:34 
QuestionHow to open and close a Tool Window in VS 2005 (and beyond) Pin
Suresh R Iyer13-Jun-09 3:39
MemberSuresh R Iyer13-Jun-09 3:39 
GeneralExpanded Toggle Macro Pin
konmel8-Apr-09 14:49
Memberkonmel8-Apr-09 14:49 
QuestionHow to open and close a Tool Window Pin
gkuehn27-Sep-07 22:32
Membergkuehn27-Sep-07 22:32 
GeneralAutoHide makes it even better Pin
Odenni26-Jan-04 8:19
MemberOdenni26-Jan-04 8:19 
GeneralRe: AutoHide makes it even better Pin
Kevin McFarlane27-Jan-04 3:18
MemberKevin McFarlane27-Jan-04 3:18 
GeneralThe proper way to toggle Pin
Kevin McFarlane31-Jul-03 4:30
MemberKevin McFarlane31-Jul-03 4:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 14 May 2002


13 bookmarked