HtmlTaskPane 类

定义

代表与在其中编辑表单的当前窗口关联的自定义任务窗格。

public ref class HtmlTaskPane abstract : Microsoft::Office::InfoPath::TaskPane
public abstract class HtmlTaskPane : Microsoft.Office.InfoPath.TaskPane
type HtmlTaskPane = class
    inherit TaskPane
Public MustInherit Class HtmlTaskPane
Inherits TaskPane
继承
HtmlTaskPane

示例

在以下示例中, Item[] 类的 TaskPaneCollection 属性用于获取对 TaskPane 表示自定义任务窗格的 对象的引用,该窗格转换为 类型 HtmlTaskPane 。 然后,代码调用 Navigate(String) 类的 HtmlTaskPane 方法来打开 HTML 文件,该文件将替换作为自定义任务窗格加载的当前 HTML 文件。

// Get a reference to the custom task pane. 
// It is always index [0] in the TaskPanes collection.
HtmlTaskPane oTaskPane = (Microsoft.Office.InfoPath.HtmlTaskPane)
   (this.CurrentView.Window.TaskPanes[0]);

// Navigate to new task pane based on url specified.
oTaskPane.Navigate("taskpane2.html");
' Get a reference to the custom task pane. It is always index (0) in 
' the TaskPanes collection.
Dim oTaskPane As HtmlTaskPane = _
   DirectCast(Me.CurrentView.Window.TaskPanes(0), _
   Microsoft.Office.InfoPath.HtmlTaskPane)

' Navigate to new task pane based on url specified.
oTaskPane.Navigate("taskpane2.html")

在以下示例中,类的 TaskPaneCollectionItem 属性用于获取对TaskPane表示自定义任务窗格的 对象的引用。 然后,代码使用 HtmlDocument 类的 HtmlTaskPane 属性调用自定义任务窗格的 HTML 代码中定义的脚本函数。

为了能够使用指定为自定义任务窗格的 HTML 文件的对象模型,可以使用 Microsoft HTML 对象库 (MSHTML.dll) 提供的对象模型。 若要从托管代码执行此操作,请在 Visual Studio 2012 中的“添加引用”对话框的“.NET”选项卡上添加对 Microsoft.mshtml 的引用。

以下示例假定表单代码文件的声明部分有一个 using mshtml; 或 Imports mshtml 指令。

// Ensure View has loaded before trying to access the task pane.
if (this.CurrentView != null)
{
   // Get a reference to the custom task pane. It is always index [0]
   // in the TaskPanes collection.
   HtmlTaskPane custom = (Microsoft.Office.InfoPath.HtmlTaskPane)
      this.CurrentView.Window.TaskPanes[0];

   // Get a reference to the custom task pane document.
   IHTMLDocument2 oHTMLdoc = (IHTMLDocument2)custom.HtmlDocument;

   // Ensure that the task pane is completely loaded.
   if (custom != null && oHTMLdoc.readyState == "complete")
   {
      // Get a reference to the parent window of the task pane. 
      IHTMLWindow2 window = (IHTMLWindow2)custom.HtmlWindow;

      // Create array to contain method arguments.
      object[] args = new object[] { "ViewID" };

      // Call into script through CLR late binding mechanism
      window.GetType().InvokeMember(
         "SelectView",      // late bound method name.
         System.Reflection.BindingFlags.InvokeMethod | // binding flags
         System.Reflection.BindingFlags.DeclaredOnly |
         System.Reflection.BindingFlags.Public |
         System.Reflection.BindingFlags.Instance,
         null,     // binder object
         window,   // target object
         args);   // method arguments
   }
}
' Ensure View has loaded before trying to access the task pane.
If Not (Me.CurrentView Is Nothing) Then
   ' Get a reference to the custom task pane. It is always index (0)
   ' in the TaskPanes collection.
   Dim custom As HtmlTaskPane = _
      DirectCast(Me.CurrentView.Window.TaskPanes(0), _
      Microsoft.Office.InfoPath.HtmlTaskPane)

   ' Get a reference to the custom task pane document.
   Dim oHTMLdoc As IHTMLDocument2 = DirectCast(
      custom.HtmlDocument, IHTMLDocument2)

   ' Ensure that the task pane is completely loaded.
   If Not (custom Is Nothing And oHTMLdoc.readyState = "complete") Then
      ' Get a reference to the parent window of the task pane.
      Dim window As IHTMLWindow2 = DirectCast(custom.HtmlWindow, _
         IHTMLWindow2

      ' Create array to contain method arguments.
        Dim args As Object()
        args = New Object() {"ViewID"}

        ' Call into script through CLR late binding mechanism
        window.GetType().InvokeMember( _
         "SelectView", _
         System.Reflection.BindingFlags.InvokeMethod Or _
         System.Reflection.BindingFlags.DeclaredOnly Or _
         System.Reflection.BindingFlags.Public Or _
         System.Reflection.BindingFlags.Instance, _
         Nothing, _
         window, _
         args)
    End If
End If

注解

仅在将表单模板的兼容性设置为“InfoPath 编辑器”时,才能在表单模板中使用 InfoPath 自定义任务窗格。 若要设置表单模板的兼容性,请单击“文件”选项卡,单击“表单选项”,再单击“兼容性”类别。

对象 HtmlTaskPane 提供用于处理 InfoPath 自定义任务窗格的属性和方法,并且还继承 类的属性 TaskPane

可供 InfoPath 任务窗格使用的属性由所使用的任务窗格的类型确定。 TaskPaneType如果 属性返回 TaskPaneType.Html,则任务窗格是自定义任务窗格,可用属性和方法由 HtmlTaskPane 类提供。 如果 属性 TaskPaneType 返回任何其他值,则任务窗格是内置任务窗格,属性由 TaskPane 类提供。

属性TaskPaneType 返回枚举 TaskPaneType 定义的值。 这些枚举值还用作 类的 TaskPaneCollection 属性的参数Item[TaskPaneType],用于返回对指定类型的任务窗格的引用。

若要启用某个自定义任务窗格并将其添加到表单模板,必须首先创建一个或多个 HTML 文件,然后在表单模板设计模式下使用“数据”选项卡上的“资源文件”命令添加这些文件作为资源文件。 然后,您必须采用以下方法配置其中一个 HTML 文件作为表单模板的默认自定义任务窗格:单击“文件”选项卡,单击“表单选项”,单击“编程”类别,然后选中“启用自定义任务窗格”复选框。

注意:无法从事件的事件处理程序Loading中调用 对象的属性和方法HtmlTaskPane,因为发生此事件时视图尚未加载,并且任务窗格与视图相关联。

构造函数

HtmlTaskPane()

代表与在其中编辑表单的当前窗口关联的自定义任务窗格。

属性

HtmlDocument

获取对 MSHTML IHTMLDocument2 接口的引用,以便使用自定义任务窗格的 HTML 文档对象模型。

HtmlWindow

获取对 MSHTML IHTMLWindow2 接口的引用,以便使用自定义任务窗格的 HTML 文档。

TaskPaneType

获取一个 TaskPaneType 值,该值指示 对象表示 TaskPane 的任务窗格的类型。

(继承自 TaskPane)
Visible

获取或设置对象表示 TaskPane 的任务窗格在 Microsoft InfoPath 用户界面中是否可见。

(继承自 TaskPane)

方法

Navigate(String)

将指定的 HTML 文档加载到自定义任务窗格中。

适用于