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

現在のドキュメントの場所を示す URL を表す Uri。


このプロパティを設定することは、Navigate メソッドを呼び出して、指定した URL を渡すことと同じです。
WebBrowser コントロールは、ブラウジング セッション時に閲覧したすべての Web ページの履歴リストを保持します。Url プロパティを設定すると、WebBrowser コントロールは指定された URL に移動し、履歴リストの末尾にその URL を追加します。
WebBrowser コントロールは、最近訪れたサイトの Web ページをローカル ハード ディスク上のキャッシュに格納します。ページごとに、キャッシュ内で存続できる時間を示す有効期限を指定できます。コントロールがページ間を移動するとき、移動先のページがキャッシュに残っている場合は、そのページをダウンロードし直すのではなく、キャッシュされたバージョンを表示することにより、表示時間を短縮します。Refresh メソッドを使用すると、WebBrowser コントロールは現在のページをダウンロードして再読み込みを実行し、確実に最新のバージョンが表示されるようにします。
![]() |
---|
別のドキュメントが要求された場合でも、このプロパティには現在のドキュメントの URL が格納されます。このプロパティに値を設定した後、すぐに値を再取得すると、WebBrowser コントロールで新しいドキュメントを読み込む時間がなかった場合、取得された値が設定された値と異なっていることがあります。 |

Url プロパティを使用して WebBrowser コントロールにアドレス バーを実装する方法を次のコード例に示します。この例では、webBrowser1 という名前の WebBrowser コントロール、TextBoxAddress という名前の TextBox コントロール、および ButtonGo という名前の Button コントロールがフォームに含まれていることを前提としています。テキスト ボックスに URL を入力し、Enter キーを押すか [移動] ボタンをクリックすると、WebBrowser コントロールが、指定された URL に移動します。ハイパーリンクをクリックして移動した場合、テキスト ボックスが自動的に更新され、現在の URL が表示されます。
' Navigates to the URL in the address box when ' the ENTER key is pressed while the ToolStripTextBox has focus. Private Sub toolStripTextBox1_KeyDown( _ ByVal sender As Object, ByVal e As KeyEventArgs) _ Handles toolStripTextBox1.KeyDown If (e.KeyCode = Keys.Enter) Then Navigate(toolStripTextBox1.Text) End If End Sub ' Navigates to the URL in the address box when ' the Go button is clicked. Private Sub goButton_Click( _ ByVal sender As Object, ByVal e As EventArgs) _ Handles goButton.Click Navigate(toolStripTextBox1.Text) End Sub ' Navigates to the given URL if it is valid. Private Sub Navigate(ByVal address As String) If String.IsNullOrEmpty(address) Then Return If address.Equals("about:blank") Then Return If Not address.StartsWith("http://") And _ Not address.StartsWith("https://") Then address = "http://" & address End If Try webBrowser1.Navigate(New Uri(address)) Catch ex As System.UriFormatException Return End Try End Sub ' Updates the URL in TextBoxAddress upon navigation. Private Sub webBrowser1_Navigated(ByVal sender As Object, _ ByVal e As WebBrowserNavigatedEventArgs) _ Handles webBrowser1.Navigated toolStripTextBox1.Text = webBrowser1.Url.ToString() End Sub
// Navigates to the URL in the address box when // the ENTER key is pressed while the ToolStripTextBox has focus. private void toolStripTextBox1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { Navigate(toolStripTextBox1.Text); } } // Navigates to the URL in the address box when // the Go button is clicked. private void goButton_Click(object sender, EventArgs e) { Navigate(toolStripTextBox1.Text); } // Navigates to the given URL if it is valid. private void Navigate(String address) { if (String.IsNullOrEmpty(address)) return; if (address.Equals("about:blank")) return; if (!address.StartsWith("http://") && !address.StartsWith("https://")) { address = "http://" + address; } try { webBrowser1.Navigate(new Uri(address)); } catch (System.UriFormatException) { return; } } // Updates the URL in TextBoxAddress upon navigation. private void webBrowser1_Navigated(object sender , WebBrowserNavigatedEventArgs e) { toolStripTextBox1.Text = webBrowser1.Url.ToString(); }
// Navigates to the URL in the address text box when // the ENTER key is pressed while the text box has focus. void TextBoxAddress_KeyDown( Object^ /*sender*/, System::Windows::Forms::KeyEventArgs^ e ) { if ( e->KeyCode == System::Windows::Forms::Keys::Enter && !this->TextBoxAddress->Text->Equals( "" ) ) { this->WebBrowser1->Navigate( this->TextBoxAddress->Text ); } } // Navigates to the URL in the address text box when // the Go button is clicked. void ButtonGo_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ ) { if ( !this->TextBoxAddress->Text->Equals( "" ) ) { this->WebBrowser1->Navigate( this->TextBoxAddress->Text ); } } // Updates the URL in TextBoxAddress upon navigation. void WebBrowser1_Navigated( Object^ /*sender*/, System::Windows::Forms::WebBrowserNavigatedEventArgs^ /*e*/ ) { this->TextBoxAddress->Text = this->WebBrowser1->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.Url プロパティのページへのリンク