Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 4
HtmlElement Class
 DomElement Property
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2010/.NET Framework 4

Other versions are also available for the following:
.NET Framework Class Library
HtmlElement..::.DomElement Property

Gets an unmanaged interface pointer for this element.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
Visual Basic
Public ReadOnly Property DomElement As Object
C#
public Object DomElement { get; }
Visual C++
public:
property Object^ DomElement {
    Object^ get ();
}
F#
member DomElement : Object

Property Value

Type: System..::.Object
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.

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

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker