WebBrowser.Url 속성

정의

현재 문서의 URL을 가져오거나 설정합니다.

public:
 property Uri ^ Url { Uri ^ get(); void set(Uri ^ value); };
[System.ComponentModel.Bindable(true)]
[System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.WebBrowserUriTypeConverter))]
public Uri Url { get; set; }
[System.ComponentModel.Bindable(true)]
[System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.WebBrowserUriTypeConverter))]
public Uri? Url { get; set; }
[<System.ComponentModel.Bindable(true)>]
[<System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.WebBrowserUriTypeConverter))>]
member this.Url : Uri with get, set
Public Property Url As Uri

속성 값

Uri

현재 문서의 URL을 나타내는 Uri입니다.

특성

예외

WebBrowser 인스턴스가 더 이상 유효하지 않은 경우

내부 ActiveX IWebBrowser2 컨트롤에서 WebBrowser 인터페이스 구현에 대한 참조를 검색할 수 없는 경우

이 속성을 설정할 때 지정된 값이 절대 URI가 아닌 경우. 자세한 내용은 IsAbsoluteUri를 참조하세요.

예제

다음 코드 예제를 사용 Url 하는 방법에 설명 합니다 속성에 대 한 주소 표시줄을 구현 하는 WebBrowser 컨트롤입니다. 이 예제에서는 양식에 라는 컨트롤, TextBox 라는 webBrowser1컨트롤 및 라는 TextBoxAddressButtonGo컨트롤이 Button 포함되어 WebBrowser 야 합니다. 텍스트 상자에 URL을 입력하고 Enter 키를 누르거나 이동 단추를 클릭하면 컨트롤이 WebBrowser 지정된 URL로 이동합니다. 하이퍼링크를 클릭하여 탐색하면 텍스트 상자가 자동으로 업데이트되어 현재 URL이 표시됩니다.

// 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();
}
// 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 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

설명

이 속성을 설정하는 것은 메서드를 Navigate 호출하고 지정된 URL을 전달하는 것과 같습니다.

컨트롤은 WebBrowser 검색 세션 중에 방문한 모든 웹 페이지의 기록 목록을 유지 관리합니다. 속성을 설정 Url 하면 컨트롤이 WebBrowser 지정된 URL로 이동하여 기록 목록의 끝에 추가합니다.

컨트롤은 WebBrowser 최근에 방문한 사이트의 웹 페이지를 로컬 하드 디스크의 캐시에 저장합니다. 각 페이지는 캐시에 남아 있는 기간을 나타내는 만료 날짜를 지정할 수 있습니다. 컨트롤이 페이지로 이동하면 페이지를 다시 다운로드하는 대신 캐시된 버전(사용 가능한 경우)을 표시하여 시간을 절약합니다. 메서드를 Refresh 사용하여 컨트롤을 WebBrowser 다운로드하여 컨트롤이 현재 페이지를 다시 로드하도록 하여 컨트롤에 최신 버전이 표시되는지 확인합니다.

참고

이 속성은 다른 문서가 요청된 경우에도 현재 문서의 URL을 포함합니다. 이 속성의 값을 설정한 다음 즉시 다시 검색하면 컨트롤에 새 문서를 로드할 시간이 없는 경우 WebBrowser 검색된 값이 설정된 값과 다를 수 있습니다. 이벤트 처리기에서 새 값을 검색할 DocumentCompleted 수 있습니다.

적용 대상

추가 정보