WebBrowserNavigatingEventArgs WebBrowserNavigatingEventArgs WebBrowserNavigatingEventArgs WebBrowserNavigatingEventArgs Class

定义

Navigating 事件提供数据。Provides data for the Navigating event.

public ref class WebBrowserNavigatingEventArgs : System::ComponentModel::CancelEventArgs
public class WebBrowserNavigatingEventArgs : System.ComponentModel.CancelEventArgs
type WebBrowserNavigatingEventArgs = class
    inherit CancelEventArgs
Public Class WebBrowserNavigatingEventArgs
Inherits CancelEventArgs
继承
WebBrowserNavigatingEventArgsWebBrowserNavigatingEventArgsWebBrowserNavigatingEventArgsWebBrowserNavigatingEventArgs

示例

下面的代码示例演示如何使用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 webBrowser1为的控件。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

注解

事件在WebBrowser控件导航到新文档之前发生。 WebBrowser.NavigatingThe WebBrowser.Navigating event occurs before the WebBrowser control navigates to a new document. 如果尚未满足某些条件 (例如, 当用户未完全填写表单时), 则可处理此事件, 以便在开始之前取消导航。You can handle this event to cancel navigation before it begins if certain conditions have not been met, for example, when the user has not completely filled out a form. 为此, 请将传递Cancel到事件处理WebBrowserNavigatingEventArgs程序的对象的属性设置为trueTo do this, set the Cancel property of the WebBrowserNavigatingEventArgs object passed to the event handler to true. 还可以使用此对象通过Url属性检索新文档的位置。You can also use this object to retrieve the location of the new document through the Url property. 如果新文档将显示在网页框架中, 则可以通过TargetFrameName属性检索框架的名称。If the new document will be displayed in a Web page frame, you can retrieve the name of the frame through the TargetFrameName property.

构造函数

WebBrowserNavigatingEventArgs(Uri, String) WebBrowserNavigatingEventArgs(Uri, String) WebBrowserNavigatingEventArgs(Uri, String) WebBrowserNavigatingEventArgs(Uri, String)

初始化 WebBrowserNavigatingEventArgs 类的新实例。Initializes a new instance of the WebBrowserNavigatingEventArgs class.

属性

Cancel Cancel Cancel Cancel

获取或设置指示是否应取消事件的值。Gets or sets a value indicating whether the event should be canceled.

(Inherited from CancelEventArgs)
TargetFrameName TargetFrameName TargetFrameName TargetFrameName

获取网页框架的名称,新文档将加载到此框架中。Gets the name of the Web page frame in which the new document will be loaded.

Url Url Url Url

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

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

适用于

另请参阅