WebBrowser.Navigating 이벤트

정의

WebBrowser 컨트롤에서 새 문서를 탐색하기 전에 발생합니다.

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

이벤트 유형

예제

다음 코드 예제에 대 한 처리기를 사용 하는 방법에 설명 합니다 Navigating : Web 페이지 form가 작성 하지 않은 탐색을 취소 하는 이벤트입니다. Document 속성 폼 입력된 필드에 값이 포함 되어 있는지 확인 하는 데 사용 됩니다.

이 예제에서는 양식에 라는 webBrowser1 컨트롤이 포함되어 WebBrowser 있고 양식 클래스에 COM에서 액세스할 수 있는 컨트롤이 ComVisibleAttribute 있어야 합니다.

전체 코드 예제는 참조에 다음 코드를 붙여넣을 수 있습니다 방법: Windows Forms 애플리케이션에 웹 브라우저 기능 추가합니다.

private void Form1_Load(object sender, EventArgs e)
{
    webBrowser1.DocumentText =
        "<html><body>Please enter your name:<br/>" +
        "<input type='text' name='userName'/><br/>" +
        "<a href='http://www.microsoft.com'>continue</a>" +
        "</body></html>";
    webBrowser1.Navigating += 
        new WebBrowserNavigatingEventHandler(webBrowser1_Navigating);
}

private void webBrowser1_Navigating(object sender, 
    WebBrowserNavigatingEventArgs e)
{
    System.Windows.Forms.HtmlDocument document =
        this.webBrowser1.Document;

    if (document != null && document.All["userName"] != null && 
        String.IsNullOrEmpty(
        document.All["userName"].GetAttribute("value")))
    {
        e.Cancel = true;
        System.Windows.Forms.MessageBox.Show(
            "You must enter your name before you can navigate to " +
            e.Url.ToString());
    }
}
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) _
    Handles Me.Load

    webBrowser1.DocumentText = _
        "<html><body>Please enter your name:<br/>" & _
        "<input type='text' name='userName'/><br/>" & _
        "<a href='http://www.microsoft.com'>continue</a>" & _
        "</body></html>"

End Sub

Private Sub webBrowser1_Navigating( _
    ByVal sender As Object, ByVal e As WebBrowserNavigatingEventArgs) _
    Handles webBrowser1.Navigating

    Dim document As System.Windows.Forms.HtmlDocument = _
        webBrowser1.Document
    If document IsNot Nothing And _
        document.All("userName") IsNot Nothing And _
        String.IsNullOrEmpty( _
        document.All("userName").GetAttribute("value")) Then

        e.Cancel = True
        MsgBox("You must enter your name before you can navigate to " & _
            e.Url.ToString())
    End If

End Sub

설명

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

처리할 수 있습니다는 Navigating 양식을 완전히 사용자가 작성 하지 않은 것 예를 들어, 특정 조건이 충족 되지 않은 경우 탐색을 취소 하는 이벤트입니다. 탐색을 취소 하려면 합니다 Cancel 의 속성을 WebBrowserNavigatingEventArgs 이벤트 처리기에 전달 된 개체 true합니다. 통해 새 문서의 URL을 검색 하려면이 개체를 사용할 수도 있습니다는 WebBrowserNavigatingEventArgs.Url 속성입니다. 웹 페이지 프레임에 표시할 새 문서를 통해 프레임의 이름을 검색할 수 있습니다는 WebBrowserNavigatingEventArgs.TargetFrameName 속성입니다.

처리를 Navigated 이벤트 알림을 받을 때의 WebBrowser 컨트롤 탐색을 완료 하 고 새 위치에 문서 로드를 시작한 합니다. 처리를 DocumentCompleted 이벤트 알림을 받을 때의 WebBrowser 컨트롤이 새 문서 로드를 완료할 합니다.

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

적용 대상

추가 정보