Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

HtmlTaskPane Class (Microsoft.Office.InfoPath)

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

Namespace: Microsoft.Office.InfoPath
Assembly: Microsoft.Office.InfoPath (in microsoft.office.infopath.dll)

public abstract class HtmlTaskPane : TaskPane

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.

The TaskPaneType 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 Tools menu 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 Form Options on the Tools menu, clicking the Programming category, and then selecting the Enable custom task pane check box.

NoteNote:

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.

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

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 Microsoft Visual Studio Tools for Applications (VSTA) or Visual Studio.

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

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

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

Community Additions

ADD
Show:
© 2015 Microsoft