WebBrowser.Navigated 이벤트

정의

WebBrowser 컨트롤에서 새 문서를 탐색하여 문서 로드를 시작한 경우 발생합니다.

public:
 event System::Windows::Forms::WebBrowserNavigatedEventHandler ^ Navigated;
public event System.Windows.Forms.WebBrowserNavigatedEventHandler Navigated;
public event System.Windows.Forms.WebBrowserNavigatedEventHandler? Navigated;
member this.Navigated : System.Windows.Forms.WebBrowserNavigatedEventHandler 
Public Custom Event Navigated As WebBrowserNavigatedEventHandler 
Public Event Navigated As WebBrowserNavigatedEventHandler 

이벤트 유형

예제

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

전체 코드 예제를 보려면 방법: Windows Forms 애플리케이션에 웹 브라우저 기능 추가합니다.

// 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

설명

WebBrowser 컨트롤 집합은 다음 속성 중 하나 또는 메서드가 호출 될 때마다 새 문서를 탐색 합니다.

처리를 Navigated 이벤트 알림을 받을 때의 WebBrowser 컨트롤이 새 문서를 탐색 합니다. 경우는 Navigated 새 문서를 통해 로드 된 콘텐츠에 액세스할 수 있습니다 즉 로드가 시작 이벤트가 발생 합니다 Document, DocumentText, 및 DocumentStream 속성입니다. 처리를 DocumentCompleted 이벤트 알림을 받을 때의 WebBrowser 컨트롤이 새 문서 로드를 완료할 합니다.

이벤트를 처리하여 탐색을 시작하기 전에 알림을 받을 수도 있습니다 Navigating . 이 이벤트를 처리하면 특정 조건이 충족되지 않은 경우(예: 사용자가 양식을 완전히 작성하지 않은 경우) 탐색을 취소할 수 있습니다.

이벤트 처리에 대한 자세한 내용은 이벤트 처리 및 발생 을 참조하십시오.

적용 대상

추가 정보