CustomTaskPane Class (2007 System)

Represents a custom task pane in a Microsoft Office application.

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

Syntax

'Declaration
Public NotInheritable Class CustomTaskPane _
    Implements IDisposable
'Usage
Dim instance As CustomTaskPane
public sealed class CustomTaskPane : IDisposable
public ref class CustomTaskPane sealed : IDisposable
public final class CustomTaskPane implements IDisposable

Remarks

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.

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.

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 Overview.

Examples

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 myUserControl1 As MyUserControl
Private WithEvents myCustomTaskPane As Microsoft.Office.Tools.CustomTaskPane

Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) _
    Handles Me.Startup

    myUserControl1 = New MyUserControl()
    myCustomTaskPane = Me.CustomTaskPanes.Add(myUserControl1, "New Task Pane")

    With myCustomTaskPane
        .DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionFloating
        .Height = 500
        .Width = 500
        .DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionRight
        .Width = 300
        .Visible = True 
    End With 
End Sub 

Private Sub myCustomTaskPane_DockPositionChanged(ByVal sender As Object, _
    ByVal e As EventArgs) Handles myCustomTaskPane.DockPositionChanged

    Dim taskPane As Microsoft.Office.Tools.CustomTaskPane = _
        TryCast(sender, Microsoft.Office.Tools.CustomTaskPane)

    If taskPane IsNot Nothing Then 

        ' Adjust sizes of user control and flow panel to fit current task pane size. 
        Dim userControl As MyUserControl = TryCast(taskPane.Control, MyUserControl)
        Dim paneSize As System.Drawing.Size = _
            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 Or _
            taskPane.DockPosition = _
            Office.MsoCTPDockPosition.msoCTPDockPositionBottom Then

            userControl.FlowPanel.FlowDirection = _
                System.Windows.Forms.FlowDirection.LeftToRight
        Else
            userControl.FlowPanel.FlowDirection = _
                System.Windows.Forms.FlowDirection.TopDown
        End If 
    End If 
End Sub
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;
        }
    }
}

Inheritance Hierarchy

System.Object
  Microsoft.Office.Tools.CustomTaskPane

Thread Safety

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

See Also

Reference

CustomTaskPane Members

Microsoft.Office.Tools Namespace

Other Resources

Getting Started Programming Application-Level Add-Ins

Custom Task Panes Overview

Managing Custom Task Panes in Multiple Application Windows

How to: Add a Custom Task Pane to an Application

Walkthrough: Automating an Application from a Custom Task Pane