HtmlElement.DomElement プロパティ

定義

この要素のアンマネージ インターフェイスへのポインターを取得します。

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

プロパティ値

要素の COM IUnknown ポインター。これを IHTMLElementなど HTML 要素のインターフェイスの 1 つにキャストできます。

次のコード例では、アンマネージド インターフェイスを使用して、現在選択されているテキストを取得し、ユーザーが選択した URL を持つハイパーリンクに変換します。 このコードは、フォームに という名前WebBrowser1のコントロールがありWebBrowser、アンマネージド 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 は、コンポーネント オブジェクト モデル (COM) を使用して記述された Internet Explorer ドキュメント オブジェクト モデル (DOM) のラッパーです。 など、基になる COM インターフェイスで、露出されていないプロパティまたはメソッドにアクセスする必要がある場合は、 IHTMLElementこのオブジェクトを使用してクエリを実行できます。

アンマネージド インターフェイスを使用するには、MSHTML ライブラリ (mshtml.dll) をアプリケーションにインポートする必要があります。 ただし、 メソッドを使用して、未露光のプロパティとメソッドを Invoke 実行することもできます。

適用対象

こちらもご覧ください