Creates a new tool window and hosts a user-defined, .NET control in it.
Namespace:
EnvDTE80
Assembly:
EnvDTE80 (in EnvDTE80.dll)
Visual Basic (Declaration)
Function CreateToolWindow2 ( _
Addin As AddIn, _
Assembly As String, _
Class As String, _
Caption As String, _
GuidPosition As String, _
<OutAttribute> ByRef ControlObject As Object _
) As Window
Dim instance As Windows2
Dim Addin As AddIn
Dim Assembly As String
Dim Class As String
Dim Caption As String
Dim GuidPosition As String
Dim ControlObject As Object
Dim returnValue As Window
returnValue = instance.CreateToolWindow2(Addin, _
Assembly, Class, Caption, GuidPosition, _
ControlObject)
Window CreateToolWindow2(
AddIn Addin,
string Assembly,
string Class,
string Caption,
string GuidPosition,
out Object ControlObject
)
Window^ CreateToolWindow2(
AddIn^ Addin,
String^ Assembly,
String^ Class,
String^ Caption,
String^ GuidPosition,
[InAttribute] [OutAttribute] Object^% ControlObject
)
function CreateToolWindow2(
Addin : AddIn,
Assembly : String,
Class : String,
Caption : String,
GuidPosition : String,
ControlObject : Object
) : Window
Before invoking CreateToolWindow2 to create a new tool window, you should either move the User control (ControlObject) into the same assembly as the add-in, or set all of the attributes on the User control to make it fully visible to COM. (For example, checking the Register for COM interop option in the project's compile options.) If you do not do this, then the control will not marshal correctly and CreateToolWindow2 will return a null value.
If you attempt to set visibility states of the new tool window — such as height, width, or position — before the tool window is visible, you get an error. Make sure that the window is visible before attempting to set any such properties.
For more examples of how to use this method, see the ToolWindow sample on the Visual Studio Automation Samples Web page: http://www.microsoft.com/downloads/details.aspx?familyid=3ff9c915-30e5-430e-95b3-621dccd25150&displaylang=en. For information about creating ActiveX controls, see Creating an MFC ActiveX Control.
The following example requires that you first create a User control by building a Windows Control Library project. Note the name of the control's project and class for use in the following code. Change the assemblypath string to the directory of the User control's DLL file. Also, the code is designed to replace the OnConnection method of an add-in project.
[C#]
public void OnConnection(object application, ext_ConnectMode
connectMode, object addInInst, ref Array custom)
{
_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;
EnvDTE80.Windows2 wins2obj;
AddIn addinobj;
object ctlobj = null;
Window newWinobj;
// A toolwindow must be connected to an add-in, so this line
// references one.
addinobj = _applicationObject.AddIns.Item(1);
wins2obj = (Windows2)_applicationObject.Windows;
// This section specifies the path and class name of the windows
// control that you want to host in the new tool window, as well as
// its caption and a unique GUID.
string assemblypath = "C:\\temp\\WindowsControlLibrary1.dll";
string classname = "WindowsControlLibrary1.UserControl1";
string guidpos = "{426E8D27-3D33-4fc8-B3E9-9883AADC679F}";
string caption = "CreateToolWindow2 Test";
// Create the new tool window and insert the user control in it.
newWinobj = wins2obj.CreateToolWindow2(addinobj, assemblypath,
classname, caption, guidpos, ref ctlobj);
newWinobj.Visible = true;
}
Reference
Other Resources