Export (0) Print
Expand All

CustomTaskPane Class

Represents a custom task pane in a Microsoft Office application.

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

public sealed class CustomTaskPane : IDisposable

Use the CustomTaskPane class 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 more information about creating custom task panes, see Custom Task Panes Overview.

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.

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 event handlers for the DockPositionChanged and VisibleChanged events. To compile this example, copy the code into the ThisAddIn class in an add-in project for an application that supports custom task panes. Make sure that you replace the default ThisAddIn_Startup method in the ThisAddIn class with the ThisAddIn_Startup method in this example.

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 =
        Office.MsoCTPDockPosition.msoCTPDockPositionFloating;
    myCustomTaskPane.Height = 500;
    myCustomTaskPane.Width = 500;
    myCustomTaskPane.DockPositionRestrict =
        Office.MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoHorizontal;
    myCustomTaskPane.Visible = true;

    myCustomTaskPane.VisibleChanged += 
        new EventHandler(myCustomTaskPane_VisibleChanged);
    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)
    {
        if (taskPane.DockPosition ==
            Office.MsoCTPDockPosition.msoCTPDockPositionFloating)
        {
            taskPane.Height = 500;
            taskPane.Width = 500;
        }
    }
}
 
private void myCustomTaskPane_VisibleChanged(object sender, EventArgs e)
{
    Microsoft.Office.Tools.CustomTaskPane taskPane =
        sender as Microsoft.Office.Tools.CustomTaskPane;

    if (taskPane != null)
    {
        if (taskPane.Visible)
        {
            taskPane.DockPosition = 
                Office.MsoCTPDockPosition.msoCTPDockPositionRight;
        }
    }
}

System.Object
  Microsoft.Office.Tools.CustomTaskPane

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft