WebBrowserNavigatingEventArgs クラス
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)


WebBrowser.Navigating イベントは、WebBrowser コントロールが新しいドキュメントに移動する前に発生します。このイベントを利用すると、たとえばユーザーがフォームにすべて入力していない場合など、特定の条件が満たされなかった場合に、ナビゲーションが開始される前にナビゲーションをキャンセルできます。これを行うには、イベント ハンドラに渡される WebBrowserNavigatingEventArgs オブジェクトの Cancel プロパティを true に設定します。また、このオブジェクトを使用して新しいドキュメントの場所を Url プロパティで取得することもできます。新しいドキュメントを Web ページのフレームに表示する場合、TargetFrameName プロパティでフレーム名を取得できます。

WebBrowser.Navigating イベントのハンドラを使用して、Web ページのフォームが入力されていない場合にナビゲーションをキャンセルする方法を次のコード例に示します。WebBrowser.Document プロパティを使用してフォームの入力フィールドに値が含まれているかどうかを判別します。この例は、フォームに webBrowser1 という WebBrowser コントロールが存在することを前提にしています。
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
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()); } }

System.EventArgs
System.ComponentModel.CancelEventArgs
System.Windows.Forms.WebBrowserNavigatingEventArgs


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


WebBrowserNavigatingEventArgs メンバ
System.Windows.Forms 名前空間
CancelEventArgs.Cancel
TargetFrameName
Url
WebBrowser クラス
WebBrowser.Navigating イベント
Weblioに収録されているすべての辞書からWebBrowserNavigatingEventArgs クラスを検索する場合は、下記のリンクをクリックしてください。

- WebBrowserNavigatingEventArgs クラスのページへのリンク