WebBrowser.Url プロパティとは? わかりやすく解説

WebBrowser.Url プロパティ

メモ : このプロパティは、.NET Framework version 2.0 で新しく追加されたものです。

現在のドキュメントの場所を示す URL を取得または設定します。

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

<BindableAttribute(True)> _
Public Property Url As Uri
Dim instance As WebBrowser
Dim value As Uri

value = instance.Url

instance.Url = value
[BindableAttribute(true)] 
public Uri Url { get; set;
 }
[BindableAttribute(true)] 
public:
property Uri^ Url {
    Uri^ get ();
    void set (Uri^ value);
}
/** @property */
public Uri get_Url ()

/** @property */
public void set_Url (Uri value)

プロパティ値
現在のドキュメントの場所を示す URL を表す Uri。

例外例外
例外の種類条件

ObjectDisposedException

この WebBrowser インスタンスは無効になっています。

InvalidOperationException

IWebBrowser2 の実装への参照を、基になる ActiveX WebBrowser から取得できませんでした。

ArgumentException

このプロパティの設定時に指定された値が、絶対 URI ではありません。詳細については、「Uri.IsAbsoluteUri」を参照してください。

解説解説

このプロパティを設定することは、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();
}

.NET Framework のセキュリティ.NET Framework のセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「WebBrowser.Url プロパティ」の関連用語

WebBrowser.Url プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



WebBrowser.Url プロパティのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS