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。
示例
下面的代码示例使用非托管接口获取当前选定的文本并将其转换为超链接,并使用用户选择的 URL。 此代码是在假设窗体具有 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是使用组件对象模型(COM)编写的Internet Explorer文档对象模型(DOM)的包装器。 如果需要访问基础 COM 接口上的未公开属性或方法,可以使用 IHTMLElement此对象来查询它们。
若要使用非托管接口,需要将 MSHTML 库(mshtml.dll)导入应用程序。 但是,也可以使用该方法 Invoke 执行未公开的属性和方法。