Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

CustomTaskPaneCollection.Add Method (UserControl, String)

Creates a new CustomTaskPane and adds it to the current CustomTaskPaneCollection. The custom task pane is based on the specified UserControl and has the specified title.

Namespace: Microsoft.Office.Tools
Assembly: Microsoft.Office.Tools.Common2007 (in microsoft.office.tools.common2007.dll)

public CustomTaskPane Add (
	UserControl control,
	string title



A UserControl that provides the user interface for the new custom task pane.


The title that appears in the title bar of the new custom task pane.

Return Value

A CustomTaskPane that represents the new custom task pane.

Exception typeCondition


control or title is a null reference (Nothing in Visual Basic).


The Dispose method has already been called on the CustomTaskPaneCollection.

Use this method to create a new CustomTaskPane that is associated with the active window of the Microsoft Office application. Although the CustomTaskPaneCollection class is a collection of CustomTaskPane objects, the Add method accepts UserControl objects instead of CustomTaskPane objects. For more information, see Custom Task Panes Overview.

If you want to associate the custom task pane with a specified window, use the Add(UserControl,String,Object) method.

The following code example demonstrates how to create a custom task pane by using the Add(UserControl,String) method. The example also uses properties of the CustomTaskPane object to modify the default appearance of the custom task pane. This code example is part of a larger example provided for the CustomTaskPane class.

private MyUserControl myUserControl1;
private Microsoft.Office.Tools.CustomTaskPane myCustomTaskPane;

private void ThisAddIn_Startup(object sender, System.EventArgs e)
    myUserControl1 = new MyUserControl();
    myCustomTaskPane = this.CustomTaskPanes.Add(myUserControl1, 
        "New Task Pane");

    myCustomTaskPane.DockPosition =
    myCustomTaskPane.Height = 500;
    myCustomTaskPane.Width = 500;
    myCustomTaskPane.DockPositionRestrict =
    myCustomTaskPane.Visible = true;

    myCustomTaskPane.VisibleChanged += 
        new EventHandler(myCustomTaskPane_VisibleChanged);
    myCustomTaskPane.DockPositionChanged += 
        new EventHandler(myCustomTaskPane_DockPositionChanged);

© 2015 Microsoft