VsPackage 2010 How to host Windows Forms User Control in Visual Studio Tool Window

by Syed Aziz ur Rahman 14. September 2012 15:38

I recently started learning how to extend Visual Studio using packages. I will be posting more about it. Here is the first thing I learned today. Do not mind about the site layout. I will fix it soon.

When we create a new VS Package project with ToolWindow, by default a control MyControl.xaml will be added which will be tied to the ToolWindow. I do not have expertise in WPF and its controls. Therefore I tried to use normal winforms user controls. I added a new usercontrol in the project and changed the code in the MyToolWindow.cs to use that control but all I see is a blank Toolwindow when I debug the project.

//Normal code in auto generated MyToolWindow.cs
base.Content = new MyControl();

//The usercontrol i created is SimpleControl. I have changed the code to.
base.Content = new SimpleControl();


Here is the snapshot of the code and solution exploror.

Snapshot of a auto generated project


I searched a lot for the simple question. I was not able to get any answer. I knew that it should be very simple. I found another guy asking the same question on stackoverflow here but no answer. Finally posted the question on MSDN forum. Mr. Ed Dore was nice enough to answer it here. I am cross posting it here for more visibility in search engine.

The ToolWindowPane can be used to host WPF content or a Winform control.

For a Winform control, you just need to override the Window property get, and leave the Content property null.

For example:

public MyToolWindow() :  base(null)
        this.Caption = Resources.ToolWindowTitle;
        this.BitmapResourceID = 301;
        this.BitmapIndex = 1;
        control = new MyControl();

     override public System.Windows.Forms.IWin32Window Window
            return (System.Windows.Forms.IWin32Window)control;

I hope this will help someone.

Tags: ,

DotNet | VSX

SORA License NJ
SORA License NJ
9/9/2013 8:20:33 PM #

Finally, recognize that your Coast Guard educational benefits can open doors to a new high paying career field by paying for you to attend an HVAC school. In addition, with the advent and popularity of Mixed Martial Arts today, our candidates are going to be faced with adversaries that may have some specialized training of their own. Just as felons right now are using newer techniques to fulfill their schemes, it is just right for agencies to be more than on par with the minds of these evildoers.

Also visit my weblog -  SORA License NJ - http://www.youtube.com/watch?v=ovu7FTs13Nk

kot w butach online
kot w butach online
9/11/2013 9:42:58 PM #

I like the helpful info you provide in your articles. I will bookmark your weblog and check again here frequently. I'm quite certain I will learn many new stuff right here! Good luck for the next!

My blog ::  kot w butach online - http://is.gd/39tHfg

9/28/2013 3:10:13 PM #

You really make it appear so easy together with your presentation however I in finding this topic to be really something that I feel I'd never understand. It sort of feels too complicated and very vast for me. I am having a look forward to your subsequent put up, I'll try to get the hold of it!

Feel free to surf to my site: schools by address ( Walker - systematicmusicology.org/w/index.php5?title=User:AlexandraAthald )

investigate this site
investigate this site
9/28/2013 6:33:51 PM #

So, isn't it better to simply let the professionals best suited for carrying out such tasks. They sometimes come with new home warranties and if you are working with the builder, you are sometimes able to make specific choices to suit your tastes in regard to flooring, windows and kitchens. Every time, more energy efficient and money-saving electrical products are hailing to the market and people are attracted towards them without knowing their basics and associated advantages.

Take a look at my web site  investigate this site - wiki.hedgehogcentral.com/tiki-index.php

sneak a peek here
sneak a peek here
9/29/2013 12:28:04 PM #

Cleaning processes should be completed within the specified time frame. Subsequent, see if the area has a web site of their private. You are also going to need to think about things like how the carpet looks and feels.

Here is my web-site;  sneak a peek here - histopedia.de/index.php

10/12/2013 9:14:53 PM #

Average hourly salary rates supplied to pharmacy assistants variety from $9. The sorts of looks released rear soon after drums could expose many components of this organ in query. That stated, an ECG offers four major pieces of information for the medical doctor.

Here is my webpage ::  MDF One - https://www.diigo.com/user/ericapalmos

I read this paragraph fully regarding the comparison of most recent and earlier technologies, it's remarkable article.

My web-site;  diet plan to lose weight fast in a week - s252691945.onlinehome.us/.../?document_srl=451207

spawarki inwertorowe
spawarki inwertorowe
11/6/2013 2:28:32 AM #

What a material of un-ambiguity and preserveness of precious experience regarding unpredicted feelings.

my weblog:  spawarki inwertorowe - http://spawarki.radom.pl

11/20/2013 2:59:18 PM #

My website  ´╗┐catering düsseldorf - a1000k.com/index.php?a=stats&u=lettie30ryp

I could not resist commenting. Well written!

my website ::  pokerstars double or nothing sng strategy - 1stopcostarica.com/must-increase-your-line-income-attempt-marketing-video

MDF 777
MDF 777
11/27/2013 4:53:23 PM #

Every time you might be in a bind and are not able to determine out where to look for a stethoscope assessment, on the internet is usually a fantastic destination to start off. The stethoscope right now is utilized that can help the health professionals keep the clients healthy. The moment the bandage has become wound all-around the cotton pad you may secure it with one particular or two basic safety pins. It is actually throughout the numerous moments I have broken the news and comforted households which i realized--we need the dying much more than they require us. Using this mentioned, it merely ensures that you need a chest piece that is tuned to get a particular overall body sound.

my page  MDF One - www.injertodecabello.net/viewupdate.php?id=158010

Powered by BlogEngine.NET
Original Design by Laptop Geek, Adapted by onesoft