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.


[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, Visual Studio Code and Azure DevOps.
We Are
  • onlyutkarsh
    Utkarsh Shigihalli
    Microsoft MVP, Technologist & DevOps Coach


  • arora_tarun
    Tarun Arora
    Microsoft MVP, Author & DevOps Coach at Avanade

Do you like our posts? Subscribe to our newsletter!
Our Book