CustomTaskPaneCollection 接口

代表 Microsoft Office 应用程序中的自定义任务窗格集合。

命名空间:  Microsoft.Office.Tools
程序集:  Microsoft.Office.Tools.Common(在 Microsoft.Office.Tools.Common.dll 中)

语法

声明
<GuidAttribute("c3a84bf1-e95b-4d23-952d-59e35673958e")> _
Public Interface CustomTaskPaneCollection _
    Inherits IEnumerable(Of CustomTaskPane), IEnumerable, IDisposable
[GuidAttribute("c3a84bf1-e95b-4d23-952d-59e35673958e")]
public interface CustomTaskPaneCollection : IEnumerable<CustomTaskPane>, 
    IEnumerable, IDisposable

CustomTaskPaneCollection 类型公开以下成员。

属性

  名称 说明
公共属性 Count 获取当前 CustomTaskPaneCollection 中的 CustomTaskPane 对象的数目。
公共属性 Item 获取指定索引处的 CustomTaskPane

页首

方法

  名称 说明
公共方法 Add(UserControl, String) 创建新的 CustomTaskPane 并将它添加到当前的 CustomTaskPaneCollection 中。自定义任务窗格基于指定的 UserControl 并具有指定的标题。
公共方法 Add(UserControl, String, Object) 创建新的 CustomTaskPane 并将它添加到当前的 CustomTaskPaneCollection 中。自定义任务窗格基于指定的 UserControl,具有指定的标题,并且与指定的应用程序窗口关联。
公共方法 BeginInit 基础结构。
公共方法 Dispose 执行与释放或重置非托管资源相关的应用程序定义的任务。 (继承自 IDisposable。)
公共方法 EndInit 基础结构。
公共方法 GetEnumerator() 返回一个循环访问集合的枚举数。 (继承自 IEnumerable<CustomTaskPane>。)
公共方法 GetEnumerator() 返回一个循环访问集合的枚举数。 (继承自 IEnumerable。)
公共方法 Remove 从 CustomTaskPaneCollection 中移除指定的 CustomTaskPane
公共方法 RemoveAt 移除 CustomTaskPaneCollection 的指定索引处的 CustomTaskPane

页首

备注

在应用程序级外接程序中使用 CustomTaskPaneCollection 对象可以向应用程序添加自定义任务窗格,移除自定义任务窗格或者访问现有的自定义任务窗格。 若要访问 CustomTaskPaneCollection 对象,请使用挂接程序项目中 ThisAddIn 类的 CustomTaskPanes 字段。 有关更多信息,请参见 应用程序级外接程序编程

任务窗格是通常停靠在应用程序窗口一侧的用户界面面板。 有关如何创建自定义任务窗格的更多信息,请参见自定义任务窗格概述

提示

此接口由 Visual Studio Tools for Office 运行时实现。不应在代码中实现此接口。有关更多信息,请参见 Visual Studio Tools for Office Runtime 概述

用法

本文档介绍面向 .NET Framework 4 的 Office 项目中所用此类型的版本。在面向 .NET Framework 3.5 的项目中,此类型可能具有不同的成员,因此本文档为此类型提供的代码示例可能并不适用。有关在面向 .NET Framework 3.5 的项目中使用此类型的文档,请参见 Visual Studio 2008 文档中以下参考部分:https://go.microsoft.com/fwlink/?LinkId=160658

示例

下面的代码示例演示如何使用 Add(UserControl, String) 方法创建自定义任务窗格。 该示例还使用 CustomTaskPane 对象的属性来修改自定义任务窗格的默认外观。 此代码示例摘自为 CustomTaskPane 提供的一个更大的示例。

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 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);
}

请参见

参考

Microsoft.Office.Tools 命名空间

其他资源

应用程序级外接程序编程

自定义任务窗格概述

在多个应用程序窗口中管理自定义任务窗格

如何:向应用程序中添加自定义任务窗格

演练:从自定义任务窗格自动化应用程序