WebBrowserNavigatingEventArgs.Url WebBrowserNavigatingEventArgs.Url WebBrowserNavigatingEventArgs.Url WebBrowserNavigatingEventArgs.Url Property

定义

获取 WebBrowser 控件要导航到的文档所在的位置。Gets the location of the document to which the WebBrowser control is navigating.

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

属性值

一个 Uri,表示 WebBrowser 控件要导航到的文档所在的位置。A Uri representing the location of the document to which the WebBrowser control is navigating.

示例

下面的代码示例演示如何使用的处理程序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

安全性

WebPermission
用于访问当前的 URL。for accessing the current URL. 关联的枚举: ConnectAssociated enumerations: Connect

适用于

另请参阅