Export (0) Print
Expand All

CustomTaskPane Interface

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Represents a custom task pane in a Microsoft Office application.

Namespace:  Microsoft.Office.Tools
Assemblies:   Microsoft.Office.Tools.Common.v4.0.Utilities (in Microsoft.Office.Tools.Common.v4.0.Utilities.dll)
  Microsoft.Office.Tools.Outlook.v4.0.Utilities (in Microsoft.Office.Tools.Outlook.v4.0.Utilities.dll)
  Microsoft.Office.Tools.Excel.v4.0.Utilities (in Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)
  Microsoft.Office.Tools.Common (in Microsoft.Office.Tools.Common.dll)
  Microsoft.Office.Tools.Word.v4.0.Utilities (in Microsoft.Office.Tools.Word.v4.0.Utilities.dll)

[GuidAttribute("881b42fd-484d-4494-8500-779de4e4aac1")]
public interface CustomTaskPane : IDisposable

The CustomTaskPane type exposes the following members.

  NameDescription
Public propertyControlGets the UserControl that provides the user interface of the custom task pane.
Public propertyDockPositionGets or sets a value that specifies where the custom task pane is located relative to the application window.
Public propertyDockPositionRestrictGets or sets a value that prevents the custom task pane from being docked in the specified position.
Public propertyHeightGets or sets the height of the custom task pane, in points.
Public propertyTitleGets the title of the custom task pane.
Public propertyVisibleGets or sets a value that specifies whether the custom task pane is visible.
Public propertyWidthGets or sets the width of the custom task pane, in points.
Public propertyWindowGets the document window that the custom task pane is associated with.
Top

  NameDescription
Public methodDisposePerforms application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. (Inherited from IDisposable.)
Top

  NameDescription
Public eventDockPositionChangedOccurs when the user changes the dock position of the custom task pane, or when code changes the value of the DockPosition property.
Public eventVisibleChangedOccurs when the user displays or closes the custom task pane, or when code changes the value of the Visible property.
Top

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.

NoteNote

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.

Usage

This documentation describes the version of this type that is used in Office projects that target the .NET Framework 4 and the .NET Framework 4.5. 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: http://go.microsoft.com/fwlink/?LinkId=160658.

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 =
        Office.MsoCTPDockPosition.msoCTPDockPositionFloating;
    myCustomTaskPane.Height = 500;
    myCustomTaskPane.Width = 500;

    myCustomTaskPane.DockPosition =
        Office.MsoCTPDockPosition.msoCTPDockPositionRight;
    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 ==
            Office.MsoCTPDockPosition.msoCTPDockPositionBottom)
        {
            userControl.FlowPanel.FlowDirection =
                System.Windows.Forms.FlowDirection.LeftToRight;
        }
        else
        {
            userControl.FlowPanel.FlowDirection =
                System.Windows.Forms.FlowDirection.TopDown;
        }
    }
}
Show:
© 2014 Microsoft