Tool windows can be positioned in various ways within the IDE: you can float tool windows around within the overall IDE container, you can dock a tool window to one of the sides of the IDE, you can join windows and pin and unpin them, and so on. (See the section “Managing the Many Windows of the IDE” in Chapter 2, “The Visual Studio IDE,” for an introduction to window layout.)
A linked window refers to two or more tool windows that have been aggregated together. Figure 14.4 shows one common example of this; the Toolbox window and the Solution Explorer window have been joined in a common frame. You can view each window that is part of the frame by clicking its tab.
By joining two or more tool windows, you actually create an additional window object (called a linked window or window frame) that functions as the container for its hosted tool windows and is available as part of the DTE.Windows
collection.
By using the Window.LinkedWindows
and Window.WindowFrame
properties and the Windows2.CreateLinkedWindowFrame
method, you can programmatically link and unlink any available tool windows. The C# code in Listing 14.5 demonstrates this process by doing the following:
1. Selecting the window objects for the Toolbox window and the Solution Explorer window.
2. Programmatically joining these two windows, effectively creating the linked window shown in Figure 14.4.
3. Obtaining a reference to the newly created linked window and using its LinkedWindows
property to unlink the windows that were previously linked.
using System;
using Extensibility;
using EnvDTE;
using EnvDTE80;
using Microsoft.VisualBasic;
using System.Windows.Forms;
public class Connect : IDTExtensibility2
{
private DTE2 _applicationObject;
private AddIn _addInInstance;
public void LinkUnLink()
{
Windows windows = _applicationObject.Windows;
//Grab references to the Solution Explorer and the Toolbox
Window solExplorer =
windows.Item(EnvDTE.Constants.vsWindowKindSolutionExplorer);
Window toolbox = windows.Item(EnvDTE.Constants.vsWindowKindToolbox);
//Use the Windows2 collection to create a linked window/window
//frame to hold the Toolbox and Solution Explorer windows
Window windowFrame;
windowFrame = windows.CreateLinkedWindowFrame(solExplorer,
toolbox, vsLinkedWindowType.vsLinkedWindowTypeTabbed);
//At this point, we have created a linked window with two tabbed
//"interior" windows: the Solution Explorer, and the Toolbox...
MessageBox.Show("Press OK to Unlink the windows", "LinkUnLink",
MessageBoxButtons.OK, MessageBoxIcon.None);
//To unlink the windows:
// — Use the window frame's LinkedWindows collection
// — Remove the window objects from this collection
windowFrame.LinkedWindows.Remove(toolbox);
windowFrame.LinkedWindows.Remove(solExplorer);
}
}