HtmlTaskPane.HtmlDocument 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取对 MSHTML IHTMLDocument2 接口的引用,以便使用自定义任务窗格的 HTML 文档对象模型。
public:
abstract property System::Object ^ HtmlDocument { System::Object ^ get(); };
public abstract object HtmlDocument { get; }
member this.HtmlDocument : obj
Public MustOverride ReadOnly Property HtmlDocument As Object
属性值
与自定义任务窗格的 HTML 文件关联的 IHTMLDocument2 对象。
示例
以下示例假定表单代码文件的声明部分有一个 using mshtml; 或 Imports mshtml 指令。
在以下示例中,类的 HtmlTaskPaneHtmlDocument 属性用于设置对完全受信任的窗体的自定义任务窗格的 HTML 窗口对象的引用。 然后,代码将更改自定义任务窗格的背景色。
// 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"
在以下示例中,HtmlTaskPane 类的 HtmlDocument 属性用于设置对完全信任表单的自定义任务窗格的 HTML window 对象的引用。 然后,代码将调用在自定义任务窗格的 HTML 代码中定义的 TaskPaneSwitchView 自定义函数。
// 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)
注解
使用 HtmlDocument 属性,可以通过晚期绑定调用包含在任务窗格的 HTML 代码中的脚本函数,如下面的第二个示例所示。 也可以使用 IHTMLDocument2 接口提供的任意属性和方法,直接处理任务窗格的 HTML 代码。
若要使用 HtmlDocument 属性返回的 IHTMLDocument2 对象,必须在 Visual Studio 2012 中的“添加引用”对话框的 “.NET” 选项卡上添加对 Microsoft.mshtml 的引用。 此外,必须将 HtmlDocument 属性返回的对象转换为 IHTMLDocument2 类型。
此成员只能由与当前打开的表单在相同域中运行的表单访问,或者由已授予跨域权限的表单访问。
可以通过 Microsoft InfoPath Filler 中打开的表单中运行的代码访问此类型或成员。