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.