HtmlTaskPane class

Represents the custom task pane that is associated the current window in which a form is being edited.

Inheritance hierarchy

System.Object
  Microsoft.Office.InfoPath.TaskPane
    Microsoft.Office.InfoPath.HtmlTaskPane

Namespace:  Microsoft.Office.InfoPath
Assembly:  Microsoft.Office.InfoPath (in Microsoft.Office.InfoPath.dll)

Syntax

'Declaration
Public MustInherit Class HtmlTaskPane _
    Inherits TaskPane
'Usage
Dim instance As HtmlTaskPane
public abstract class HtmlTaskPane : TaskPane

Remarks

InfoPath custom task panes can only be used in a form template with the compatibility set to InfoPath Editor. To set a form template's compatibility, click the File tab, click Form Options, and then click the Compatibility category.

The HtmlTaskPane object provides properties and methods for working with InfoPath custom task panes, and it also inherits the properties of the TaskPane class.

The properties available for an InfoPath task pane are determined by the type of task pane that you are working with. If the TaskPaneType property returns TaskPaneType.Html, the task pane is a custom task pane and the properties and methods available are provided by the HtmlTaskPane class. If the TaskPaneType property returns any other value, the task pane is a built-in task pane and the properties are provided by the TaskPane class.

TheTaskPaneType property returns values defined by the TaskPaneType enumeration. These enumerated values are also used as arguments to the Item[TaskPaneType] property of the TaskPaneCollection class for returning a reference to a specified type of task pane.

To enable and add a custom task pane to a form template, you must first create one or more HTML files and add them as resource files using the Resource Files command on the Data tab in form template design mode. Then, you must configure one of the HTML files as the form template's default custom task pane, by clicking the File tab, clicking Form Options, clicking the Programming category, and then selecting the Enable custom task pane check box.

Note

The properties and methods of the HtmlTaskPane object cannot be called from an event handler for the Loading event because the view is not yet loaded when this event occurs, and task panes are associated with the view.

Examples

In the following example, the Item property of the TaskPaneCollection class is used to get a reference to the TaskPane object that represents the custom task pane, which is cast to the HtmlTaskPane type. The code then calls the Navigate method of the HtmlTaskPane class to open an HTML file, which replaces the current HTML file that is loaded as the custom task pane.

// 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")

In the following example, the Item property of the TaskPaneCollection class is used to get a reference to the TaskPane object that represents the custom task pane. The code then calls a scripting function defined in the HTML code of the custom task pane by using the HtmlDocument property of the HtmlTaskPane class.

To be able to work with the object model of the HTML file that is specified as a custom task pane, you use the object model provided by the Microsoft HTML Object Library (MSHTML.dll). To do that from managed code, add a reference to Microsoft.mshtml on the .NET tab of the Add Reference dialog box in Visual Studio 2012.

The following example assumes that you have a using mshtml; or Imports mshtml directive in the declarations section of your form code file.

// 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

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

HtmlTaskPane members

Microsoft.Office.InfoPath namespace