Hosting Windows Forms controls in the Office Task Pane

OK, here's a question I hear frequently: I want a richer user interface in my Smart Document task pane than the default controls allow.  I know I can add ActiveX controls in there, but we've standardised on .NET as our development platform now.  Can I create a user control in managed code and expose it as an ActiveX control using COM interop, then host it in the task pane?


The short answer to this is no.  The longer answer goes like this:

In .NET Framework 1.0 the hosting of managed Windows Forms controls in unmanaged hosts was supported in exactly one unmanaged host: Microsoft Internet Explorer.  No other popular COM control hosts, like MFC, Visual Basic 6.0, or ATL, were supported in version 1.0. While neither Visual Basic 6.0 nor ATL is officially supported in version 1.1 either, the Windows Forms team did a full test cycle on hosting Windows Forms controls as COM controls in MFC 7.1—the version of MFC that comes with Visual Studio .NET 2003—and it is now an officially supported unmanaged host.  The upshot of this is that as of today, managed controls are not supported in the Office task pane.  If you try to do it you will very likely have problems getting the controls to accept the focus, or even getting the controls to render at all.


Now the good news is that technology is in the pipeline that will solve this problem: Visual Studio Tools for Office 2005 provides a task pane design surface onto which you can add any .NET control.  Not only that it provides many more advances too: the ability to program the task pane without requiring an XML schema be attached to the document, the ability to add any managed control directly onto the surface of a document or spreadsheet, and a server-side model for manipulation of data stored in .doc and .xls files.


So, to sum up, if you want a rich user interface to sit alongside a Word or Excel document and support the user as they are working with a document, these are your options:

  1. Create your ActiveX control in unmanaged code and host it in a Smart Document Task Pane today.  The downside of this is that you are investing in developing a solution that will become legacy technology almost as soon as it is complete.
  2. If your solution won't ship until mid-2005, then get started using the Visual Studio Tools for Office 2005 Beta and make use of this and all the other goodies it brings.
  3. Create a VSTO 1.0 solution that uses a modeless window to host a managed user control today.  With a little work you could get the window to resize itself in a smart way, a little like the Help window does in Office 2003.  Then, when VSTO 2005 ships it should be pretty easy to migrate the user control to the VSTO Task Pane.  For my money this is a great compromise approach.  Whilst you don't get to host your controls in the task pane today, you do get all the advantages of working with managed code, a neat upgrade path to VSTO 2005 and the knowledge that the investment you make in writing user controls now won't be wasted when the next version of VSTO ships.
Comments (6)

  1. Wamiq Ansari says:

    Hi Mark,

    I have a question with regards to your point 3 in the above post that says ‘Create a VSTO 1.0 solution that uses a modeless window to host a managed user control today’.

    I am trying to do this by bringing up a WinForm when a button on the task pane is clicked. The WinForm comes up fine as long as it contains System.Windows.Forms Controls. As soon as I enter a third party managed control by Infragistics the WinForm Fails to come up without throwing up an exception.

    I would just like to know if what I’m trying to do complies with your point 3 in the post. Otherwise, please mention if this would be achievable through VSTO 2005.

    Thanks again,

    Wamiq Ansari

  2. Wamiq Ansari says:

    Hi Mark,

    I have done bit more investigation on as to why my ‘modeless window’ fails without exception.

    As I mentioned in my previous post, this modeless window contains a managed control provided by Infragistics. There is an assembly called ‘Infragistics.Win.v3.2.dll’ that contains this control. This assembly is signed by Infragistics and placed in my GAC.

    My Smart Document Solution loads all the required dlls and I think it fails when it comes to loading this particular dll, from an AppDomain that is spawned by MS WORD.

    Do I have to play with this AppDomains Security settings for it to load this Infragistics dll from GAC.

    Thanks in advance,

    Wamiq Ansari

  3. Mark Bower says:

    Aaah! You need to explicitly apply full trust to the Infragistics assembly. The VSTO loader revokes full trust for All Code and Zone based security evidence. There’s more details on the VSTO team blog:

  4. Wamiq Ansari says:

    Hi Mark,

    Thanks very much, it all started to work when I applied full trust to Infragistics assembly. Basically, the full trust was given to all the Infragistics assemblies using a particular public key.

    Thanks again, I’ll post more if I have any more problems.

    God Bless,

    Wamiq Ansari

Skip to main content