WebBrowserNavigatingEventArgs.Url Proprietà

Definizione

Ottiene il percorso del documento su cui si sta spostando il controllo WebBrowser.

public:
 property Uri ^ Url { Uri ^ get(); };
public Uri Url { get; }
public Uri? Url { get; }
member this.Url : Uri
Public ReadOnly Property Url As Uri

Valore della proprietà

Uri

Uri che rappresenta il percorso del documento su cui si sta spostando il controllo WebBrowser.

Esempio

Nell'esempio di codice seguente viene illustrato come usare un gestore per l'evento per annullare la WebBrowser.Navigating navigazione quando non è stato compilato un modulo di pagina Web. La WebBrowser.Document proprietà viene utilizzata per determinare se il campo di input del modulo contiene un valore. In questo esempio è necessario che il modulo contenga un WebBrowser controllo denominato 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

Si applica a

Vedi anche