Click here to Skip to main content
13,447,272 members (38,636 online)
Click here to Skip to main content
Add your own
alternative version


9 bookmarked
Posted 19 Mar 2003

Toggle Tool Windows in VS.NET

, 19 Mar 2003
Rate this:
Please Sign up or sign in to vote.
De/Activate common tool windows without using the mouse


Note: This is an enhancement of an article written by Kevin McFarlane. The original article can be found here.

When working in the .Net IDE, it's very easy to become overwhelmed by the numerous new tool windows. The macro presented here will automatically de/activate the tool windows. When the macro is called to deactivate the tool windows, it will note which tool windows are currently active before deactivating only those windows. Subsequently, only those windows that were deactivated will be re-activated. In this way, the same keyboard shortcut can be used to toggle between activating & deactivating the tool windows.


As great as the .Net IDE is, having all the tool windows open can distract the programmer from focusing on the code. For example:

Sample screenshot

Here, it’s very hard to read the code, because of all the tool windows that are open. This macro will hide all the active tool windows:

Sample screenshot

so, now it’s much easier to concentrate on the code. The next invocation of the macro will restore all the tool windows.

Using the code

To use the macro, assign it a shortcut key. I assigned “Alt-T” to this macro, because it’s not preassigned by the IDE. Every time you press the shortcut key the tool windows will be de/activated.

Points of Interest

To check if a tool window is open, the macro calls CanToggleToolWindow:

Function CanToggleToolWindow(ByVal vsWindowKind As String, _
                             ByRef ToolWin As Window) As Boolean
        ToolWin = DTE.Windows.Item(vsWindowKind)
    Catch ex As System.IndexOutOfRangeException
        Return False
    Catch ex As System.Exception
        MsgBox(ex.GetType().ToString() & vbNewLine & vbNewLine & ex.Message)
        Return False
    End Try
    Return True
End Function

DTE.Windows.Item(vsWindowKind) throws an exception if the index is out of range. If an exception is thrown we assume that the desired tool window is not open. Therefore, we will not de/activate that tool window. Otherwise, a reference to the window is returned.

To toggle a single tool window, use

Sub ToggleToolWindow(ByVal vsWindowKind As String, ByRef ShouldToggle As Boolean)
    Dim ToolWin As Window

    If (Not CanToggleToolWindow(vsWindowKind, ToolWin)) Then
        ShouldToggle = False
        Exit Sub
    End If

    If (ToolWindowsAreVisible) Then
        If (ToolWin.Visible()) Then
            ShouldToggle = True
        End If
        ToolWin.Visible = False
        If (ShouldToggle) Then
            ToolWin.Visible = True
        End If
    End If
End Sub

The ShouldToggle parameter indicates whether the macro deactivated this window the last time. The variable ToolWindowsAreVisible is a toggle which controls de/activation.

Using the above two routines, the macro to toggle the tool windows is coded as:

Sub Toggle_Tool_Windows()

    'DESCRIPTION: Closes/Opens tool windows

    ToggleToolWindow(Constants.vsWindowKindClassView, ClassViewWasOpen)
    ToggleToolWindow(Constants.vsWindowKindCommandWindow, CommandWindowWasOpen)
    ToggleToolWindow(Constants.vsWindowKindMacroExplorer, MacroExplorerWasOpen)
    ToggleToolWindow(Constants.vsWindowKindObjectBrowser, ObjectBrowserWasOpen)
    ToggleToolWindow(Constants.vsWindowKindOutput, OutputWasOpen)
    ToggleToolWindow(Constants.vsWindowKindProperties, PropertiesWasOpen)
    ToggleToolWindow(Constants.vsWindowKindSolutionExplorer, SolutionExplorerWasOpen)
    ToggleToolWindow(Constants.vsWindowKindTaskList, TaskListWasOpen)
    ToggleToolWindow(Constants.vsWindowKindToolbox, ToolboxWasOpen)
    ToolWindowsAreVisible = (Not ToolWindowsAreVisible)

End Sub

Finally, the toggles that determine the state of the tool windows are defined as:

Dim ToolWindowsAreVisible As Boolean = True
Dim ClassViewWasOpen As Boolean
Dim CommandWindowWasOpen As Boolean
Dim MacroExplorerWasOpen As Boolean
Dim ObjectBrowserWasOpen As Boolean
Dim OutputWasOpen As Boolean
Dim PropertiesWasOpen As Boolean
Dim SolutionExplorerWasOpen As Boolean
Dim TaskListWasOpen As Boolean
Dim ToolboxWasOpen As Boolean

You can define additional tool windows by defining a toggle for the window, and calling ToggleToolWindow in Toggle_Tool_Windows.

Hope you find this article helpful.


<?xml:namespace prefix = st1 /><st1:date Month="3" Day="9" Year="2003">3/9/2003 Original version 1.0 by <st1:personname>Behnam Nikbakht


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Behnam Nikbakht
United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralSwitch to full screen Pin
Thomas Freudenberg21-Mar-03 1:14
memberThomas Freudenberg21-Mar-03 1:14 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02-2016 | 2.8.180318.3 | Last Updated 20 Mar 2003
Article Copyright 2003 by Behnam Nikbakht
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid