Share via


HtmlTaskPane.HtmlDocument Property

Gets a reference to the MSHTML IHTMLDocument2 interface for working with the the HTML document object model of a custom task pane.

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

Syntax

'Declaration
'Usage

Property Value

An IHTMLDocument2 object associated with the HTML file of the custom task pane.

Remarks

Using the HtmlDocument property, you can call scripting functions contained in the HTML code of the task pane through late binding, as in the second example below. You can also directly manipulate the HTML code of the task pane using any of the properties and methods that the IHTMLDocument2 interface provides.

To work with the IHTMLDocument2 object returned by the HtmlDocument property, you must 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. Additionally, you must cast the object returned by the HtmlDocument property to the IHTMLDocument2 type.

This member can be accessed only by forms running in the same domain as the currently open form, or by forms that have been granted cross-domain permissions.

This type or member can be accessed only from code running in forms opened in Microsoft Office InfoPath 2007.

Example

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

In the following example, the HtmlDocument property of the HtmlTaskPane class is used to set a reference to the HTML window object of the custom task pane of a fully trusted form. Then the code changes the background color of the custom task pane.

// 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 and cast to
// the IHTMLDocument2 type.
IHTMLDocument2 oHTMLdoc = (IHTMLDocument2)(custom.HtmlDocument);

// Change custom task pane background color to red.
oHTMLdoc.bgColor = "red";
' 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 and cast to
' the IHTMLDocument2 type.
IHTMLDocument2 oHTMLdoc = _
   DirectCast(custom.HtmlDocument,IHTMLDocument2)

' Change custom task pane background color to red.
oHTMLdoc.bgColor = "red"

In the following example, the HtmlDocument property of the HtmlTaskPane class is used to set a reference to the HTML window object of the custom task pane of a fully trusted form. Then the code calls the TaskPaneSwitchView custom function that is defined in the HTML code of the custom task pane.

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

   // Get a reference to the parent window of the task pane.
   IHTMLWindow2 window = (IHTMLWindow2)oHTMLdoc.parentWindow;

   // Call into script through CLR late binding mechanism.
   window.GetType().InvokeMember(
      "TaskPaneSwitchView",      // 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
      null);   // method arguments
   ' 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)

     ' Get a reference to the parent window of the task pane.
      Dim window As IHTMLWindow2 = DirectCast(oHTMLdoc.parentWindow, _
         IHTMLWindow2

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

See Also

Reference

HtmlTaskPane Class
HtmlTaskPane Members
Microsoft.Office.InfoPath Namespace