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セキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

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

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

   

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



WebBrowser.Url プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS