Author: |
Carlos J. Quintero (Microsoft MVP) |
Applies to: |
Microsoft Visual Studio 2005 |
Date: |
March 2012 |
|
Microsoft Visual Studio 2008 |
|
|
|
Microsoft Visual Studio 2010 |
Introduction
Once created, the visibility of a Visual Studio toolwindow can be in one of four states:
- Visible: the toolwindow is permanently shown. This state is reached by clicking
some button to show the toolwindow, typically in the "View" menu or a toolbar
button. The first time that a toolwindow must be shown, it has to be created
first. Subsequent times the creation is not required because toolwindows are
never destroyed, when you click the Close button they just become invisible.
- Closed: the toolwindow seems to be closed, although it is not destroyed.
This state is reached by
clicking the Close button ("X") of the toolwindow.
- Collapsed: the toolwindow is visible, but only the caption of the toolwindow is shown. This state is reached
when the toolwindow is set to autohide (with the "Auto Hide" button to the left of the
"Close" button) and it doesn't have the focus. When you hover the mouse over the
caption, the toolwindow is expanded.
- Expanded: the toolwindow is completely shown, but not permanently; as soon as
it loses the focus it will collapse to its caption. This state is reached when
the toolwindow is set to autohide and it has the focus.
The automation model EnvDTE of the original Visual Studio .NET (2002) provided
the EnvDTE.Window.Visible and EnvDTE.Window.Autohides properties to get or set
those states. However, it didn't provide events to be notified when the state of
a toolwindow changes.
The automation model EnvDTE80 introduced by Visual Studio 2005 provides the EnvDTE80.Events2.WindowVisibilityEvents class with its WindowShowing and WindowHiding events.
The article HOWTO: Detect when a Visual Studio toolwindow is shown or hidden shows how to use those events.
However, those events exhibit the following inconsistent behavior:
Transition |
Case and expected behavior |
VS 2005 |
VS 2008 |
VS 2010 |
Visible -> Closed |
When a toolwindow is closed, the WindowHiding event
should fire. |
OK |
OK |
OK |
Visible -> Collapsed |
When a toolwindow that is not set to autohide is collapsed
because you click the Autohide button, the WindowHiding event should
fire. |
OK |
OK |
OK |
Closed -> Visible |
When a toolwindow is shown again after being closed, the
WindowShowing event should fire. |
Error |
Error |
OK |
Collapsed -> Expanded |
When a toolwindow that is set to autohide is expanded
because its caption gets the focus, the WindowShowing event should
fire. |
Error |
Error |
OK |
Expanded -> Collapsed |
When a toolwindow that is set to autohide is collapsed
because it loses the focus, the WindowHiding event should fire. |
Error |
Error |
Error |
Expanded -> Visible |
When a toolwindow that is set to autohide is expanded
because the caption has the focus and then you toggle the Autohide button to
turn off autohide, the WindowShowing event should not fire
(because the toolwindow was already shown). |
Error |
Error |
Error (it fires even twice) |
Expanded -> Closed |
When a toolwindow that is set to autohide is expanded
because the caption has the focus and then you close it clicking the Close
button, the WindowHiding event should fire. |
Error |
Error |
OK |
Related articles
Go to the 'Visual Studio Extensibility (VSX)' web site for more articles like this (Articles section)
|