HtmlElement.DomElement 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
會為這個元素取得一個非管理介面指標。
public:
property System::Object ^ DomElement { System::Object ^ get(); };
public object DomElement { get; }
member this.DomElement : obj
Public ReadOnly Property DomElement As Object
屬性值
元素的 COM IUnknown 指標,你可以將其投射到 HTML 元素介面之一,例如 IHTMLElement。
範例
以下程式碼範例使用非管理介面,將當前選取的文字轉換成超連結,網址由使用者選擇。 這段程式碼是在假設你的表單有一個 WebBrowser 名為 WebBrowser1的控制項,並且你已將未管理的 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 = WebBrowser1.Document.DomDocument
If (Not (IDoc Is Nothing)) Then
Dim ISelect = IDoc.selection
If (ISelect Is Nothing) Then
MsgBox("Please select some text before using this command.")
Exit Sub
End If
Dim TxtRange = 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,你可以用這個物件來查詢它們。
若要使用非受管理介面,你需要將 MSHTML 函式庫(mshtml.dll)匯入你的應用程式。 不過,你也可以用這個 Invoke 方法執行未暴露的屬性和方法。