0 out of 2 rated this helpful - Rate this topic

HtmlElement.DomElement Property

Note: This property is new in the .NET Framework version 2.0.

Gets an unmanaged interface pointer for this element.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public Object DomElement { get; }
/** @property */
public Object get_DomElement ()

public function get DomElement () : Object

Property Value

The COM IUnknown pointer for the element, which you can cast to one of the HTML element interfaces, such as IHTMLElement.

HtmlElement is a wrapper for the Internet Explorer Document Object Model (DOM), which is written using the Component Object Model (COM). If you need to access unexposed properties or methods on the underlying COM interfaces, such as IHTMLElement, you can use this object to query for them.

In order to use the unmanaged interfaces, you will need to import the MSHTML library (mshtml.dll) into your application. However, you can also execute unexposed properties and methods using the Invoke method.

The following code example uses unmanaged interfaces to take the currently selected text and convert it into a hyperlink, with the URL chosen by the user. This code was written under the assumption that your form has a WebBrowser control named WebBrowser1, and that you have added the unmanaged MSHTML library as a reference to your project.

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

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0
Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.