HtmlElement.DomElement Property

Definition

Gets an unmanaged interface pointer for this element.

C#
public object DomElement { get; }

Property Value

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

Examples

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.

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

Remarks

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.

Applies to

Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

See also