다음을 통해 공유


WebBrowserNavigatingEventHandler 대리자

정의

컨트롤의 이벤트를 처리 Navigating 할 메서드를 WebBrowser 나타냅니다.

public delegate void WebBrowserNavigatingEventHandler(System::Object ^ sender, WebBrowserNavigatingEventArgs ^ e);
public delegate void WebBrowserNavigatingEventHandler(object sender, WebBrowserNavigatingEventArgs e);
public delegate void WebBrowserNavigatingEventHandler(object? sender, WebBrowserNavigatingEventArgs e);
type WebBrowserNavigatingEventHandler = delegate of obj * WebBrowserNavigatingEventArgs -> unit
Public Delegate Sub WebBrowserNavigatingEventHandler(sender As Object, e As WebBrowserNavigatingEventArgs)

매개 변수

sender
Object

이벤트의 출처입니다.

e
WebBrowserNavigatingEventArgs

이벤트 데이터를 포함하는 A WebBrowserNavigatingEventArgs 입니다.

예제

다음 코드 예제에서는 웹 페이지 양식이 채워지지 않은 경우 이벤트에 대한 WebBrowser.Navigating 처리기를 사용하여 탐색을 취소하는 방법을 보여 줍니다. 이 WebBrowser.Document 속성은 폼 입력 필드에 값이 포함되어 있는지 여부를 확인하는 데 사용됩니다. 이 예제에서는 양식에 라는 webBrowser1컨트롤이 WebBrowser 포함되어야 합니다.

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

설명

대리자를 WebBrowserNavigatingEventHandler 만들 때 이벤트를 처리할 메서드를 식별합니다. 이벤트를 이벤트 처리기와 연결하려면 대리자의 인스턴스를 이벤트에 추가합니다. 대리자를 제거하지 않는 한 이벤트가 발생할 때마다 이벤트 처리기가 호출됩니다. 이벤트 처리기 대리자에 대한 자세한 내용은 이벤트 처리 및 발생을 참조하세요.

확장명 메서드

Name Description
GetMethodInfo(Delegate)

지정된 대리자가 나타내는 메서드를 나타내는 개체를 가져옵니다.

적용 대상

추가 정보