WebBrowser.Navigated 이벤트
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
컨트롤이 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 . 이 예제에서는 폼에 호출된 WebBrowser 컨트롤, 호출webBrowser1된 컨트롤 및 호출TextBoxTextBoxAddress된 Button 컨트롤을 ButtonGo 포함해야 합니다. 입력란에 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 속성을 통해 DocumentTextDocumentStream액세스할 수 있습니다. 컨트롤이 DocumentCompleted 새 문서 로드를 완료할 WebBrowser 때 알림을 받을 이벤트를 처리합니다.
또한 이벤트를 처리하여 탐색을 시작하기 전에 알림을 받을 수 있습니다 Navigating . 이 이벤트를 처리하면 특정 조건이 충족되지 않은 경우 탐색을 취소할 수 있습니다( 예: 사용자가 양식을 완전히 작성하지 않은 경우).
이벤트 처리에 대한 자세한 내용은 이벤트 처리 및 발생시키기를 참조하십시오.