Compartilhar via


HtmlElement.DomElement Propriedade

Definição

Obtém o ponteiro da interface não gerenciada deste elemento.

public:
 property System::Object ^ DomElement { System::Object ^ get(); };
public object DomElement { get; }
member this.DomElement : obj
Public ReadOnly Property DomElement As Object

Valor da propriedade

Object

O ponteiro COM IUnknown para o elemento, que você pode converter em uma das interfaces de elemento HTML, como IHTMLElement.

Exemplos

O exemplo de código a seguir usa interfaces não gerenciadas para pegar o texto selecionado no momento e convertê-lo em um hiperlink, com a URL escolhida pelo usuário. Esse código foi escrito sob a suposição de que seu formulário tem um WebBrowser controle chamado WebBrowser1e que você adicionou a biblioteca MSHTML não gerenciada como uma referência ao seu projeto.

private void CreateHyperlinkFromSelection()
{
    if (webBrowser1.Document != null)
    {

        MSHTML.IHTMLDocument2 iDoc = (MSHTML.IHTMLDocument2)webBrowser1.Document.DomDocument;

        if (iDoc != null)
        {
            MSHTML.IHTMLSelectionObject iSelect = iDoc.selection;
            if (iSelect == null)
            {
                MessageBox.Show("Please select some text before using this command.");
                return;
            }

            MSHTML.IHTMLTxtRange txtRange = (MSHTML.IHTMLTxtRange)iSelect.createRange();

            // Create the link.
            if (txtRange.queryCommandEnabled("CreateLink"))
            {
                Object o = null;
                txtRange.execCommand("CreateLink", true, o);
            }
        }
    }
}
Private Sub CreateHyperlinkFromSelection()
    If (WebBrowser1.Document IsNot Nothing) Then
        Dim IDoc As mshtml.IHTMLDocument2 = WebBrowser1.Document.DomDocument

        If (Not (IDoc Is Nothing)) Then
            Dim ISelect As mshtml.IHTMLSelectionObject = IDoc.selection
            If (ISelect Is Nothing) Then
                MsgBox("Please select some text before using this command.")
                Exit Sub
            End If

            Dim TxtRange As mshtml.IHTMLTxtRange = ISelect.createRange()

            ' Create the link.
            If (TxtRange.queryCommandEnabled("CreateLink")) Then
                TxtRange.execCommand("CreateLink", True)
            End If
        End If
    End If
End Sub

Comentários

HtmlElement é um wrapper para o DOM (Modelo de Objeto de Documento) do Internet Explorer, que é escrito usando o COM (Component Object Model). Se você precisar acessar propriedades ou métodos não expostos nas interfaces COM subjacentes, como IHTMLElement, você poderá usar esse objeto para consultá-las.

Para usar as interfaces não gerenciadas, você precisará importar a biblioteca MSHTML (mshtml.dll) para seu aplicativo. No entanto, você também pode executar propriedades e métodos não expostos usando o Invoke método.

Aplica-se a

Confira também