CustomTaskPane Interface

CustomTaskPane Interface


Represents a custom task pane in a Microsoft Office application.

Namespace:   Microsoft.Office.Tools
Assembly:  Microsoft.Office.Tools.Common (in Microsoft.Office.Tools.Common.dll)

public interface CustomTaskPane : IDisposable


Gets the UserControl that provides the user interface of the custom task pane.


Gets or sets a value that specifies where the custom task pane is located relative to the application window.


Gets or sets a value that prevents the custom task pane from being docked in the specified position.


Gets or sets the height of the custom task pane, in points.


Gets the title of the custom task pane.


Gets or sets a value that specifies whether the custom task pane is visible.


Gets or sets the width of the custom task pane, in points.


Gets the document window that the custom task pane is associated with.


(Inherited from IDisposable.)


Occurs when the user changes the dock position of the custom task pane, or when code changes the value of the DockPosition property.


Occurs when the user displays or closes the custom task pane, or when code changes the value of the Visible property.

Use a CustomTaskPane object in an application-level add-in to modify a custom task pane, or to respond when the location or visibility of the custom task pane changes. Task panes are user interface panels that are typically docked to one side of an application window. For information about how to create custom task panes, see Custom Task Panes.

To control the size or location of the custom task pane, you can use properties such as Height, Width, and Visible.

To respond when the custom task pane moves or changes visibility, you can handle the DockPositionChanged and VisibleChanged events.


This interface is implemented by the Visual Studio Tools for Office runtime. It is not intended to be implemented in your code. For more information, see Visual Studio Tools for Office Runtime Overview.

This documentation describes the version of this type that is used in Office projects that target the .NET Framework 4 or later. In projects that target the .NET Framework 3.5, this type might have different members and the code examples provided for this type might not work. For documentation about this type in projects that target the .NET Framework 3.5, see the following reference section in the Visual Studio 2008 documentation:

The following code example demonstrates how to create a custom task pane by using the Add(UserControl, String) method. The example uses properties of the CustomTaskPane object to set the default appearance of the custom task pane, and it defines an event handler for the DockPositionChanged event. To compile this example, copy the code into the ThisAddIn class in an add-in project for an application that supports custom task panes. Replace the default ThisAddIn_Startup method in the ThisAddIn class with the ThisAddIn_Startup method in this example. This example also assumes that the project contains a UserControl named MyUserControl, and the UserControl contains a FlowLayoutPanel named FlowPanel.

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.DockPosition =
    myCustomTaskPane.Width = 300;

    myCustomTaskPane.Visible = true;
    myCustomTaskPane.DockPositionChanged +=
        new EventHandler(myCustomTaskPane_DockPositionChanged);

private void myCustomTaskPane_DockPositionChanged(object sender, EventArgs e)
    Microsoft.Office.Tools.CustomTaskPane taskPane =
        sender as Microsoft.Office.Tools.CustomTaskPane;

    if (taskPane != null)
        // Adjust sizes of user control and flow panel to fit current task pane size.
        MyUserControl userControl = taskPane.Control as MyUserControl;
        System.Drawing.Size paneSize = new System.Drawing.Size(taskPane.Width, taskPane.Height);
        userControl.Size = paneSize;
        userControl.FlowPanel.Size = paneSize;

        // Adjust flow direction of controls on the task pane.
        if (taskPane.DockPosition == 
            Office.MsoCTPDockPosition.msoCTPDockPositionTop ||
            taskPane.DockPosition ==
            userControl.FlowPanel.FlowDirection =
            userControl.FlowPanel.FlowDirection =
Return to top
© 2015 Microsoft