VSTO: My Favorite Feature - Custom Task Panes

My avid readers (both of you) know that I've done quite a bit of work around Outlook 2007 Form Regions in Visual Studio 2005 Tools for Office.  If you missed those posts, you can read more about them here and here.  Form Regions are a great way to add custom functionality to Outlook forms but there's another way you can add features and Windows forms to all of the Office applications and unlike Form Regions (pre-Orcas) it's really easy.  Therefore one of my favorite features is Custom Task Panes.

Adding a custom task pane couldn't be much easier.  Just add a UserControl to your Add-in project and build any functionality you'd like inside that control.  You can use the databinding features of WinForms, third party controls, and even COM+ components.  Then to use that UserControl as a custom task pane just add it to the CustomTaskPaneCollection like below.

Dim ctp As Microsoft.Office.Tools.CustomTaskPane = Me.CustomTaskPanes.Add(New MyUserControl(), "Product List")

You can then make the task pane visible either at startup or when the user clicks a button on the Ribbon.  For a great example of how to properly implement a custom task pane's visibility check out Ken Getz' MSDN Webcast.

 

By default a custom task pane is going to appear docked on the right side of the window for your application.  You can however specify where you want the custom task pane to display by using the DockPosition parameter.

ctp.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionBottom

The possible options for the DockPosition are:

  • MsoCTPDockPosition.msoCTPDockPositionBottom
  • MsoCTPDockPosition.msoCTPDockPositionFloating
  • MsoCTPDockPosition.msoCTPDockPositionLeft
  • MsoCTPDockPosition.msoCTPDockPositionRight
  • MsoCTPDockPosition.msoCTPDockPositionTop

You can also respond to the user changing the task pane's position by using the DockPositionChanged event. 

Private Sub CTP_DockPositionChanged(ByVal sender As Object, ByVal e As EventArgs)
        Dim ctp As Microsoft.Office.Tools.CustomTaskPane = CType(sender, Microsoft.Office.Tools.CustomTaskPane)
        'Do something meaningful here
End Sub

Lastly, you can restrict where the user can dock your task pane using the DockPositionRestrict property.  The possible options are:

  • msoCTPDockPositionRestrictNoChange
  • msoCTPDockPositionRestrictNoHorizontal
  • msoCTPDockPositionRestrictNone
  • msoCTPDockPositionRestrictNoVertical

And that ladies and gents is all there is to that.

6 Comments

  • Paul,

    I'm just an Office 2007 user who misses task panes - I don't know or do programming. Are there any tasks panes created similar to those in Office 2003 which I can use for my Office 2007 programs?

    Thanks,

  • The same tasks panes (Research, etc.) that were in the 2003 version exist in the 2007 version. In Outlook you can right click on the message and click on "Look up..." and that will bring up the Research Pane.

  • I believe that you can but there's little reason that I can think of to go to such great lengths just to avoid writing an Add-In. It really doesn't get any easier than what I've outlined.

  • Hello sir,


    Is it possible to create custome task pane in office 2003 whith user of VSTO 2005 and if you have download link of VSTO 2005(not SE) please tell me

    thanX,

  • Yes, for Office 2003 it works very much the same way. Read this: http://msdn.microsoft.com/en-us/library/aa537188(office.11).aspx for more information.

  • You don't create an EXE, you would need to create a setup package for your add-in that installs the DLL into the GAC and gives it the proper permissions. Check out this page: http://msdn.microsoft.com/en-us/library/bb332051.aspx

    Hope that helps

Comments have been disabled for this content.