HtmlElement.DomElement 屬性

定義

為此項目取得 Unmanaged 介面指標。

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

屬性值

Object

專案的 COM IUnknown 指標,您可以轉換成其中一個 HTML 元素介面,例如 IHTMLElement

範例

下列程式碼範例會使用 Unmanaged 介面來擷取目前選取的文字,並將它轉換成超連結,並使用使用者所選擇的 URL。 此程式碼是以假設您的表單具有 WebBrowser 名為 的 WebBrowser1 控制項,而且您已將 Unmanaged MSHTML 程式庫新增為專案的參考。

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

備註

HtmlElement 是 Internet Explorer 檔物件模型 (DOM) 的包裝函式,使用元件物件模型 (COM) 來撰寫。 如果您需要存取基礎 COM 介面上的未公開屬性或方法,例如 IHTMLElement ,您可以使用這個物件來查詢它們。

若要使用 Unmanaged 介面,您必須將 MSHTML 程式庫 (mshtml.dll) 匯入您的應用程式。 不過,您也可以使用 Invoke 方法來執行未公開的屬性和方法。

適用於

另請參閱