WebBrowser.DocumentText プロパティ
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Dim instance As WebBrowser Dim value As String value = instance.DocumentText instance.DocumentText = value
/** @property */ public String get_DocumentText () /** @property */ public void set_DocumentText (String value)
表示されるページの HTML テキスト。ドキュメントが読み込まれていない場合は、空の文字列 ("")。


文字列処理ツールを使用して、WebBrowser コントロールに表示される HTML ページのコンテンツを操作する場合に、このプロパティを使用します。このプロパティを使用すると、たとえばデータベースからページを読み込んだり、正規表現を使用してページを分析したりできます。このプロパティを設定すると、WebBrowser コントロールは自動的に about:blank URL に移動した後、指定されたテキストを読み込みます。つまり、このプロパティを設定すると Navigating イベント、Navigated イベント、および DocumentCompleted イベントが発生します。Url プロパティの値は無効になります。
Web ページのコンテンツの Stream にアクセスするには、DocumentStream プロパティを使用します。また、Document プロパティと HTML ドキュメント オブジェクト モデル (DOM: Document Object Model) を使用して、ページのコンテンツにアクセスすることもできます。
Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows CE プラットフォームメモ : .NET Compact Framework では、DocumentText を使用して Web ページのコンテンツを取得することはできませんが、このプロパティを使用して、リンクや単純な HTML フォームを提供するなど、ユーザーに HTML を提供することはできます。コード例については、「方法 : .NET Compact Framework で WebBrowser コントロールを使用する」を参照してください。

DocumentText プロパティを使用して、選択したドキュメントのコンテンツをプログラムで表示する方法を次のコード例に示します。この例は、フォームに webBrowser1 という WebBrowser コントロールが存在することを前提にしています。
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) _ Handles Me.Load webBrowser1.DocumentText = _ "<html><body>Please enter your name:<br/>" & _ "<input type='text' name='userName'/><br/>" & _ "<a href='http://www.microsoft.com'>continue</a>" & _ "</body></html>" End Sub Private Sub webBrowser1_Navigating( _ ByVal sender As Object, ByVal e As WebBrowserNavigatingEventArgs) _ Handles webBrowser1.Navigating Dim document As System.Windows.Forms.HtmlDocument = _ webBrowser1.Document If document IsNot Nothing And _ document.All("userName") IsNot Nothing And _ String.IsNullOrEmpty( _ document.All("userName").GetAttribute("value")) Then e.Cancel = True MsgBox("You must enter your name before you can navigate to " & _ e.Url.ToString()) End If End Sub
private void Form1_Load(object sender, EventArgs e) { webBrowser1.DocumentText = "<html><body>Please enter your name:<br/>" + "<input type='text' name='userName'/><br/>" + "<a href='http://www.microsoft.com'>continue</a>" + "</body></html>"; webBrowser1.Navigating += new WebBrowserNavigatingEventHandler(webBrowser1_Navigating); } private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e) { System.Windows.Forms.HtmlDocument document = this.webBrowser1.Document; if (document != null && document.All["userName"] != null && String.IsNullOrEmpty( document.All["userName"].GetAttribute("value"))) { e.Cancel = true; System.Windows.Forms.MessageBox.Show( "You must enter your name before you can navigate to " + e.Url.ToString()); } }


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


WebBrowser クラス
WebBrowser メンバ
System.Windows.Forms 名前空間
WebBrowser.Document プロパティ
WebBrowser.DocumentStream プロパティ
その他の技術情報
IWebBrowser2 インターフェイス
Weblioに収録されているすべての辞書からWebBrowser.DocumentText プロパティを検索する場合は、下記のリンクをクリックしてください。

- WebBrowser.DocumentText プロパティのページへのリンク