Export (0) Print
Expand All

HTMLTaskPane.HTMLDocument property

Gets a reference to an HTML document object of the Microsoft Office InfoPath 2003 custom task pane.

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

IHTMLDocument2 HTMLDocument { get; }

Property value

Type: IHTMLDocument2

The HTMLDocument property of the HTMLTaskPaneObject object is one of the properties inherited by the TaskPaneObject object when the type of the task pane is 0, which means that it is the custom task pane.

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 HTML document object provides.

NoteNote

Before using the HTMLDocument property of the HTMLTaskPaneObject object, you must first cast the TaskPaneObject object to an HTMLTaskPane object as shown in the examples below.

In the following example, the HTMLDocument property of the HTMLTaskPane object 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.

NoteNote

The following examples require a reference to the Microsoft.mshtml.dll assembly.

using mshtml;
public void ChangeBackgroundColor()
 {
 // Get a reference to the custom task pane. It is always index [0] in the TaskPanes collection.
  HTMLTaskPane oTaskPane = (HTMLTaskPane)thisXDocument.View.Window.TaskPanes[0];
  // Get a reference to the HTML document object of the custom task pane.
  IHTMLDocument2 oHTMLDoc = oTaskPane.HTMLDocument;
  // Change custom task pane background color to red.
  oHTMLDoc.bgColor = "red";
}

In the following example, the HTMLDocument property of the HTMLTaskPane object 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.

HTMLTaskPane custom = (HTMLTaskPane) thisXDocument.View.Window.TaskPanes[0];
mshtml.IHTMLWindow2 window = custom.HTMLDocument.parentWindow; 
// call into script through CLR late binding mechanism
custom.HTMLDocument.parentWindow.GetType().InvokeMember(
 "TaskPaneSwitchView",      // late bound method      
 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);
Show:
© 2014 Microsoft