Pieter van der Westhuizen

Add-in Express vs. VSTO: Custom Office task panes

A task pane is a dockable window which was first introduced in Microsoft Office XP. It provided a new and convenient way for users to gather information and access common features and commands. Chances are that if you've used any application in the Microsoft Office suite you would have used a task pane.

One of the task panes I use rather often is the Clipboard. You access this task pane by clicking the dialog box launcher button on the Clipboard group in applications such as Word, Excel and Outlook.

The Clipboard pane

This will then show the user a list of everything in his clipboard and give them the ability to quickly paste it into the current open document by simply clicking on the item.

The standard Office task pane is not designed to be minimized, but you can move it around and dock it to either the right or the left side of the Office application.

Creating an Office Task pane with VSTO

You can create your own custom Office Task pane with VSTO by creating a new Office Add-in project in Visual Studio.

Creating a custom Excel Task pane with VSTO

Next, you add a standard User control to your project and add UI elements and logic to it as required.

Adding a standard User control to your project

Open the ThisAddin.cs class and add the following class level variables:

private Microsoft.Office.Tools.CustomTaskPane vstoCustomTaskPane;
private VSTOTaskPaneControl myVstoTaskPaneControl;
 
Finally, add the following to the ThisAddIn_Startup event:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
    myVstoTaskPaneControl = new VSTOTaskPaneControl();
    vstoCustomTaskPane = this.CustomTaskPanes.Add(myVstoTaskPaneControl, "My VSTO Task Pane");
    vstoCustomTaskPane.Visible = true;
}

Developing an Office Task pane with Add-in Express

Creating a standard Office task pane with Add-in Express is even easier than with VSTO. As with VSTO you also need to add a standard UserControl to your Visual Studio project first. Add-in Express supports the latest Visual Studio 2012 (VB.NET, C#, C++.NET) as well as VS 2010 and lower, including the Visual Studio Express editions.

When you open the AddinModule.cs designer, you will notice it has a TaskPanes property.

TaskPanes property in the Add-in Express AddinModule properties

When you click on the ellipses (…) button next to the TaskPanes property you are shown an ADXTaskPane Collection Editor form, which you can use to add multiple Task panes. You specify which user control to use for the Office task pane by selecting it from the ControlProgID property's drop-down list. You can also choose in which Office applications the Task Pane should appear by setting the SupportedApps property.

Tuning your custom Office task pane using the ADXTaskPane Collection Editor

From here you build and register you Add-in Express project and your custom task pane will be visible when you start Excel, Word or PowerPoint.

Creating an advanced Office Task pane with Add-in Express

The standard task pane is fine if you want to show a plain old task pane. But what if you would like to give your user the choice to minimize the pane or if you would like to have more than one task pane docked to one part of the application or if you want Office Task panes in version of Office earlier than 2007?

Version independent task panes

The native Office task pane is only supported in Office 2007, Office 2010 and Office 2013. Add-in Express provides components that make creating truly version independent task panes that work in Office 2013-2000 a piece of cake. If you would like to create an advanced task pane for Excel you need to add a new ADXExcelTaskPanesManager component to the AddinModule designer. Add-in Express provides two additional task pane manager components, one for Word and another for PowerPoint.

Add-in Express advanced task pane components for Excel, Word and PowerPoint

In order to design the layout of the task pane, you add a new ADX Excel Task Pane item to your project.

Adding a new Add-in Express Excel Task Pane item to your project

This item looks like a standard user control but has built-in properties that give the developer access to the Excel.Application object as well as the ADX Excel Forms Manager. By using the Add-in Express components you can create Office task panes that work in Office 2000, XP, 2003, 2007, 2010 and Office 2013.

In-place designers

When selecting the ADX Excel Task Pane Manager component, you will notice an in-place designer, which you can use to quickly add or remove task panes to the Excel Task Panes Manager.

Using the Add-in Express in-place designer you can quickly add or remove task panes to the Excel Task Panes Manager

Each item in the collection of task pane items provides a number of properties with which you can show a header or close button for the task pane and specify a number of things including whether the user is allowed to drag and drop the task pane or minimize it.

Host multiple panes on one dock

By adding more than one item to the task pane collection and setting their Position property to the same value, will enable you to host more than one task pane per dock area. Add-in Express will automatically add visual cues in the form of arrow icons and a dropdown menu listing the available panes for the user as illustrated below.

A dropdown menu in Excel 2010 with 2 custom task panes

Drag and drop enabled out of the box

Allowing your users to drag and drop the task pane in order to dock it to another part of the application is as easy as setting the IsDragDropAllowed property to true and specifying which positions the advanced task pane can be docked to in the AllowedDropPositions property

Setting the IsDragDropAllowed property to true enables drag-and-drop for your for your advanced task pane

As with Add-in Express Advanced Outlook Regions, the user will be shown a visual cue to indicate all available docking positions.

A visual cue indicates all available docking positions for your task pane

Developer and user friendly

As with all Add-in Express components, developers are given access to a feature-rich object model that enables them to programmatically control many aspects of the task pane, including controlling the state (Minimized, Normal and Hidden), position and behaviour.

For example, highlighting the advanced Office task pane only requires a single line of code:

private void buttonFlash_Click(object sender, EventArgs e)
{
    this.Highlight();
}

Controlling the state of the task pane also only requires one line of code:

private void btnMinimize_Click(object sender, EventArgs e)
{
    this.RegionState = ADXRegionState.Minimized;
}

Add-in Express also takes care of storing the last state the user left the task pane in i.e. size, state and dock position. The developers do not need to store any of those values for the user.

As easy as that, Add-in Express enables you to create world-class, commercial quality Microsoft Add-ins with standard and advanced Task panes.

Thank you for reading. Until next time keep coding!

Last updated: 6-Feb-2013

Add-in Express vs. VSTO:

You may also be interested in:

Post a comment

Have any questions? Ask us right now!