Compartilhar via


HtmlTaskPane.HtmlDocument Propriedade

Definição

Obtém uma referência à interface IHTMLDocument2 do MSHTML para trabalhar com o modelo de objeto de documento HTML de um painel de tarefas personalizado.

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

Valor da propriedade

Um objeto IHTMLDocument2 associado ao arquivo HTML do painel de tarefas personalizado.

Exemplos

Os exemplos a seguir pressupõem que você tenha um mshtml de uso; ou importa a diretiva mshtml na seção declarações do arquivo de código do formulário.

No exemplo a seguir, a propriedade HtmlDocument da HtmlTaskPane classe é usada para definir uma referência ao objeto de janela HTML do painel de tarefas personalizado de um formulário totalmente confiável. Em seguida, o código altera a cor de segundo plano do painel de tarefas personalizado.

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

No exemplo a seguir, a propriedade HtmlDocument da classe HtmlTaskPane é usada para definir uma referência ao objeto de janela HTML do painel de tarefas personalizado de um formulário totalmente confiável. Em seguida, o código chama a função personalizada TaskPaneSwitchView que é definida no código HTML do painel de tarefas personalizado.

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

Comentários

Usando a propriedade HtmlDocument , você pode chamar funções de script contidas no código HTML do painel de tarefas por meio da associação tardia, como no segundo exemplo abaixo. Você também pode manipular diretamente o código HTML do painel de tarefas usando qualquer uma das propriedades e métodos que a interface IHTMLDocument2 fornece.

Para trabalhar com o objeto IHTMLDocument2 retornado pela propriedade HtmlDocument , você deve adicionar uma referência ao Microsoft.mshtml na guia .NET da caixa de diálogo Adicionar Referência no Visual Studio 2012. Além disso, você deve lançar o objeto retornado pela propriedade HtmlDocument para o tipo IHTMLDocument2 .

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 InfoPath Filler.

Aplica-se a