WebBrowserNavigatingEventHandler WebBrowserNavigatingEventHandler WebBrowserNavigatingEventHandler WebBrowserNavigatingEventHandler Delegate

定义

表示将处理 Navigating 控件的 WebBrowser 事件的方法。Represents the method that will handle the Navigating event of a WebBrowser control.

public delegate void WebBrowserNavigatingEventHandler(System::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 Object Object Object

事件源。The source of the event.

继承
WebBrowserNavigatingEventHandlerWebBrowserNavigatingEventHandlerWebBrowserNavigatingEventHandlerWebBrowserNavigatingEventHandler

示例

下面的代码示例演示如何使用的处理程序WebBrowser.Navigating事件取消导航时在未填写网页窗体。The following code example demonstrates how to use a handler for the WebBrowser.Navigating event to cancel navigation when a Web page form has not been filled in. WebBrowser.Document属性用于确定窗体输入的字段是否包含值。The WebBrowser.Document property is used to determine whether the form input field contains a value. 此示例要求你的窗体包含WebBrowser控件调用webBrowser1This example requires that your form contains a WebBrowser control called webBrowser1.

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 委托时,需要标识将处理该事件的方法。When you create a WebBrowserNavigatingEventHandler delegate, you identify the method that will handle the event. 若要将事件与事件处理程序关联,请将该委托的一个实例添加到事件中。To associate the event with your event handler, add an instance of the delegate to the event. 除非移除了该委托,否则每当发生该事件时就会调用事件处理程序。The event handler is called whenever the event occurs, unless you remove the delegate. 有关事件处理程序委托的详细信息,请参阅处理和引发事件For more information about event handler delegates, see Handling and Raising Events.

扩展方法

GetMethodInfo(Delegate) GetMethodInfo(Delegate) GetMethodInfo(Delegate) GetMethodInfo(Delegate)

获取指示指定委托表示的方法的对象。Gets an object that represents the method represented by the specified delegate.

适用于

另请参阅