WebBrowserNavigatingEventArgs 類別

定義

提供 Navigating 事件的資料。

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

範例

下列程式碼範例示範如何在網頁表單尚未填入時,使用 事件的處理常式 WebBrowser.Navigating 來取消流覽。 屬性 WebBrowser.Document 是用來判斷表單輸入欄位是否包含值。 此範例會要求您的表單包含 WebBrowser 名為 的 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.Navigating 事件會在控制項巡覽至新檔之前 WebBrowser 發生。 如果尚未符合特定條件,您可以處理此事件,以在開始流覽之前取消流覽,例如,當使用者尚未完整填寫表單時。 若要這樣做,請將 Cancel 傳遞至事件處理常式之 WebBrowserNavigatingEventArgs 物件的 屬性設定為 true 。 您也可以使用此物件,透過 Url 屬性擷取新檔的位置。 如果新檔會顯示在網頁框架中,您可以透過 TargetFrameName 屬性擷取框架的名稱。

建構函式

WebBrowserNavigatingEventArgs(Uri, String)

初始化 WebBrowserNavigatingEventArgs 類別的新執行個體。

屬性

Cancel

取得或設定值,這個值表示是否應該取消事件。

(繼承來源 CancelEventArgs)
TargetFrameName

取得將載入新文件的 Web 網頁框架的名稱。

Url

取得 WebBrowser 控制項所巡覽至的文件位置。

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於

另請參閱