Click here to Skip to main content
Click here to Skip to main content

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

Introduction

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.

Background

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
    Try
        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
    Else
        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.

History

3/9/2003 Original version 1.0 by Behnam Nikbakht

License

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

Share

About the Author

Behnam Nikbakht

United States United States
No Biography provided

Comments and Discussions

 
GeneralAnother Approach PinmemberRonzo31-Mar-03 11:56 
GeneralRe: Another Approach PinmemberSpieler3-Sep-03 0:22 
GeneralRe: Another Approach PinsussAaron Croft10-Oct-05 5:16 
GeneralSwitch to full screen PinmemberThomas Freudenberg21-Mar-03 1:14 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 20 Mar 2003
Article Copyright 2003 by Behnam Nikbakht
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid