Listening to tool window events in Visual Studio

Aug 3, 2013 | Utkarsh Shigihalli Utkarsh Shigihalli

Extensions VisualStudio

In this blog post we will see how to listen to toolwindow events. I am going to assume that you already know how to create toolwindows.

Tool windows are most common and widely used while you to work inside Visual Studio. If you are wondering what are tool windows inside Visual Studio, think about Solution Explorer, Immediate Window, Output Window and even Property Window. These windows are most flexible allowing you to dock, auto-hide and even support multiple monitors.

toolwindow

If you are Visual Studio extension developer, sooner or later you will be required to create tool windows in your extensions, because they integrate seamlessly inside Visual Studio.

Visual Studio SDK provides IVsWindowFrameNotify3 interface which needs to be implemented by your ToolWindowPane class. The interface IVsWindowFrameNotify3 provides methods to track close, change in dock state etc.

Note: Visual Studio fires OnClose event but does not actually close it. Instead it just hides it from the view. The actual Close event is a overridden method which is fired only when Visual Studio instance is closed.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
[Guid("6912BAC8-BD13-4B64-A675-D83902A63077")]
public class MyToolWindow : ToolWindowPane, IVsWindowFrameNotify3
{
    /// <summary>
    /// Standard constructor for the tool window.
    /// </summary>
    public MyToolWindow(): base(null)
    {
    }

    public int OnClose(ref uint pgrfSaveOptions)
    {
        return Microsoft.VisualStudio.VSConstants.S_OK;
    }

    public int OnDockableChange(int fDockable, int x, int y, int w, int h)
    {
        return Microsoft.VisualStudio.VSConstants.S_OK;
    }

    public int OnMove(int x, int y, int w, int h)
    {
        return Microsoft.VisualStudio.VSConstants.S_OK;
    }

    public int OnShow(int fShow)
    {
        return Microsoft.VisualStudio.VSConstants.S_OK;
    }

    public int OnSize(int x, int y, int w, int h)
    {
        return Microsoft.VisualStudio.VSConstants.S_OK;
    }
}
About author
Utkarsh Shigihalli
Utkarsh Shigihalli
Utkarsh is passionate about software development and has experience in the areas of Azure, Azure DevOps, C# and TypeScript. Over the years he has worked as an architect, independent consultant and manager in many countries including India, United States, Netherlands and United Kingdom. He is a Microsoft MVP and has developed numerous extensions for Visual Studio and Azure DevOps.
Comments