WebBrowserNavigatingEventHandler Delegado

Definición

Representa el método que controlará el evento Navigating de un control 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)

Parámetros

sender
Object

Origen del evento.The source of the event.

e
WebBrowserNavigatingEventArgs

Objeto WebBrowserNavigatingEventArgs que contiene los datos del evento.A WebBrowserNavigatingEventArgs that contains the event data.

Herencia
WebBrowserNavigatingEventHandler

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar un controlador WebBrowser.Navigating para que el evento cancele la navegación cuando no se ha rellenado un formulario de página web.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. La WebBrowser.Document propiedad se usa para determinar si el campo de entrada de formulario contiene un valor.The WebBrowser.Document property is used to determine whether the form input field contains a value. Este ejemplo requiere que el formulario contenga WebBrowser un control webBrowser1denominado.This 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

Comentarios

Cuando se crea un delegado WebBrowserNavigatingEventHandler, se identifica el método que controlará el evento.When you create a WebBrowserNavigatingEventHandler delegate, you identify the method that will handle the event. Para asociar el evento al controlador, se debe agregar una instancia del delegado al evento.To associate the event with your event handler, add an instance of the delegate to the event. Siempre que se produce el evento, se llama a su controlador, a menos que se quite el delegado.The event handler is called whenever the event occurs, unless you remove the delegate. Para obtener más información sobre los delegados de controladores de eventos, vea controlar y provocar eventos.For more information about event handler delegates, see Handling and Raising Events.

Métodos de extensión

GetMethodInfo(Delegate)

Obtiene un objeto que representa el método representado por el delegado especificado.Gets an object that represents the method represented by the specified delegate.

Se aplica a

Consulte también: