WebBrowser.Navigated Event
Assembly: System.Windows.Forms (in system.windows.forms.dll)
'Declaration Public Event Navigated As WebBrowserNavigatedEventHandler 'Usage Dim instance As WebBrowser Dim handler As WebBrowserNavigatedEventHandler AddHandler instance.Navigated, handler
/** @event */ public void add_Navigated (WebBrowserNavigatedEventHandler value) /** @event */ public void remove_Navigated (WebBrowserNavigatedEventHandler value)
JScript supports the use of events, but not the declaration of new ones.
The WebBrowser control navigates to a new document whenever one of the following properties is set or methods is called:
Handle the Navigated event to receive notification when the WebBrowser control has navigated to a new document. When the Navigated event occurs, the new document has begun loading, which means you can access the loaded content through the Document, DocumentText, and DocumentStream properties. Handle the DocumentCompleted event to receive notification when the WebBrowser control finishes loading the new document.
You can also receive notification before navigation begins by handling the Navigating event. Handling this event lets you cancel navigation if certain conditions have not been met, for example, the user has not completely filled out a form.
For more information about handling events, see Consuming Events.
The following code example demonstrates how to use a handler for the Navigated event to implement an address bar for the WebBrowser control. This example requires that your form contains a WebBrowser control called webBrowser1, a TextBox control called TextBoxAddress, and a Button control called ButtonGo. When you type a URL into the text box and press ENTER or click the Go button, the WebBrowser control navigates to the URL specified. When you navigate by clicking a hyperlink, the text box automatically updates to display the current URL.
For the complete code example, see How to: Add Web Browser Capabilities to a Windows Forms Application.
' Navigates to the URL in the address box when ' the ENTER key is pressed while the ToolStripTextBox has focus. Private Sub toolStripTextBox1_KeyDown( _ ByVal sender As Object, ByVal e As KeyEventArgs) _ Handles toolStripTextBox1.KeyDown If (e.KeyCode = Keys.Enter) Then Navigate(toolStripTextBox1.Text) End If End Sub ' Navigates to the URL in the address box when ' the Go button is clicked. Private Sub goButton_Click( _ ByVal sender As Object, ByVal e As EventArgs) _ Handles goButton.Click Navigate(toolStripTextBox1.Text) End Sub ' Navigates to the given URL if it is valid. Private Sub Navigate(ByVal address As String) If String.IsNullOrEmpty(address) Then Return If address.Equals("about:blank") Then Return If Not address.StartsWith("http://") And _ Not address.StartsWith("https://") Then address = "http://" & address End If Try webBrowser1.Navigate(New Uri(address)) Catch ex As System.UriFormatException Return End Try End Sub ' Updates the URL in TextBoxAddress upon navigation. Private Sub webBrowser1_Navigated(ByVal sender As Object, _ ByVal e As WebBrowserNavigatedEventArgs) _ Handles webBrowser1.Navigated toolStripTextBox1.Text = webBrowser1.Url.ToString() End Sub
- SecurityPermission for immediate callers to use this control. Demand value: LinkDemand; Named Permission Sets: FullTrust.
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
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
Reference
WebBrowser ClassWebBrowser Members
System.Windows.Forms Namespace
WebBrowser.DocumentCompleted Event
WebBrowser.DocumentStream Property
WebBrowser.DocumentText Property
GoBack
GoForward
GoHome
GoSearch
Navigate
Navigating
WebBrowser.Url Property
WebBrowserNavigatedEventArgs
WebBrowserNavigatedEventHandler