共用方式為


HTMLTaskPane.HTMLDocument 屬性

取得 Microsoft Office InfoPath 2003 自訂工作窗格的 HTML 文件物件參考。

**命名空間:**Microsoft.Office.Interop.InfoPath
**組件:**Microsoft.Office.Interop.InfoPath (於 microsoft.office.interop.infopath.dll 中)

語法

'宣告
<DispIdAttribute(4)> _
ReadOnly Property HTMLDocument As IHTMLDocument2
'用途
Dim instance As HTMLTaskPane
Dim value As IHTMLDocument2

value = instance.HTMLDocument
[DispIdAttribute(4)] 
IHTMLDocument2 HTMLDocument { get; }

備註

HTMLTaskPaneObject 物件的 HTMLDocument 屬性是當工作窗格的類型為 0 時 (表示它是自訂窗格),由 TaskPaneObject 物件繼承的屬性之一。

使用 HTMLDocument 屬性,即可如下列第二個範例所示,透過晚期繫結呼叫工作窗格之 HTML 程式碼中包含的指令碼函式,也可使用 HTML 文件物件所提供的任何屬性及方法,來直接處理工作窗格的 HTML 程式碼。

注意

如下列範例所示,在使用 HTMLTaskPaneObject 物件的 HTMLDocument 屬性之前,必須先將 TaskPaneObject 物件轉換成 HTMLTaskPane 物件。

範例

在下列範例中,HTMLTaskPane 物件的 HTMLDocument 屬性是用於設定完全信任表單自訂工作窗格的 HTML 視窗物件參照。接著程式碼會變更自訂工作窗格的背景色彩。

注意

下列範例需要 Microsoft.mshtml.dll 組件的參考。

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

在下列範例中,HTMLTaskPane 物件的 HTMLDocument 屬性是用於設定完全信任表單自訂工作窗格的 HTML 視窗物件參考。接著程式碼會呼叫自訂工作窗格其 HTML 程式碼中定義的 TaskPaneSwitchView 自訂函式。

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

請參閱

參考

HTMLTaskPane 介面
HTMLTaskPane 成員
Microsoft.Office.Interop.InfoPath 命名空間