Welcome to MSDN Blogs Sign in | Join | Help

Creating a ToolWindow hosting a .NET user control

In previous version of VS, if you want to create a ToolWindow hosting a .NET user control by using Windows.CreateToolWindow, you'll have to use a shim control to support it. Now with VS 2005, you don't need the shim any more. It is so handy by using Windows2.CreateToolWindow2, you pass the assembly location and the class name, you are able to host your .NET user control in the ToolWindow you created.
Following is a C# code snippet showing how to implement this in an add-in:

            Windows2 win = (Windows2)_applicationObject.Windows;
            object ctl = null;
            Guid g = Guid.NewGuid();
            System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
            Window myToolWin = win.CreateToolWindow2(_addInInstance, asm.Location, "MyToolWin.UserControl1", "My Tool Window", "{" + g.ToString() +"}", ref ctl);
            myToolWin.Visible = true;

One thing I want to point it out is when the User Control is not in the same assembly as the add-in, CreateToolWindow2 does not return a reference to the user control (ctl is null). You either need to move the control into the same assembly as the Add-in, or set all the attributes on the control to make it fully COM visible. Also, to make the ToolWindow show up, you need to set myToolWin.Visible = true.

 

Published Friday, September 30, 2005 2:49 PM by hlong

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Creating a ToolWindow hosting a .NET user control

Using "Guid g = Guid.NewGuid();" prevents Visual Studio remembering the docking state of your tool window.  Use a fixed GUID and it will remember it correctly.

Sunday, March 25, 2007 5:58 PM by Richie Hindle

# re: Creating a ToolWindow hosting a .NET user control

Guid can also be created by:

>go to "Tools" option in Menu.

>Create GUID option.

>Select GUID format as Registry format.

>Copy the new unique GUID.

>Pass that as 5th parameter to CreateToolWindow2.

Wednesday, December 10, 2008 4:55 AM by Nayana Kalkur

# re: Creating a ToolWindow hosting a .NET user control

You can also use g.ToString("B") to get the Guid in the correct format...

Saturday, January 03, 2009 11:58 AM by Craig Dean

# re: Creating a ToolWindow hosting a .NET user control

how to do this:

move the control into the same assembly as the Add-in

I use "add a new project" to add the dll assmebly, What should I do to move it? Just copy the files?

Tuesday, March 24, 2009 2:28 AM by Fei

# Visual Studio 2008 可扩展性开发(八):关于用户界面的种种(上)ff

前言

Add-In大多需要一定的用户界面,前面的随笔中采用的主要方式是菜单和自定义窗体。对于菜单,可以是VS的主菜单,也可以是在某个特定的上下文菜单,比如编辑器;对于自定义窗体,用起来也很简单,就...

Saturday, May 09, 2009 12:25 PM by Anders Cui

# Visual Studio 2008 可扩展性开发(八):关于用户界面的种种(上)

本文介绍了VS工具窗口相关的内容。首先是如何访问、操作那些内置的工具窗口,如Solution Explorer、Output Window等等;然后介绍了如何创建自定义的工具窗口,在这个窗口中可以查看VS的快捷键列表。

Saturday, May 09, 2009 12:25 PM by Anders Cui

# re: Creating a ToolWindow hosting a .NET user control

話題の小向美奈子ストリップを隠し撮り!入念なボディチェックをすり抜けて超小型カメラで撮影した神動画がアップ中!期間限定配信の衝撃的映像を見逃すな

Saturday, June 13, 2009 12:05 PM by 小向美奈子

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker