The WebBrowser control of windows application has various properties, methods, and events that we can use to implement user interface features similar to those found in Internet Explorer, following example show that how to navigate web browser control with URL and example also show the use of navigated() method of the control.
Navigate() method Loads the document at the location indicated by the given URL into the WebBrowser control
Following example requires one webbrowser control, one textbox as addressbar called ‘textboxURL’ and one button.
When we give some webpage address in ‘textboxURL’ textbox and click on ‘Go’ button then webbrowser control navigate page according to given address.
[Code]
enter uri in text box and click on Go button
Private Sub BtnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnGo.Click Navigate() End Sub
webbrowser control load the page according to given address:
Private Sub Navigate() Dim AddressURL As String = textBoxURL.Text If String.IsNullOrEmpty(AddressURL) Then Return End If If AddressURL.Equals("about:blank") Then Return End If If Not AddressURL.StartsWith("http://") And _ Not AddressURL.StartsWith("https://") Then AddressURL = "http://" & AddressURL End If Try WebBrowser1.Navigate(New Uri(AddressURL)) Catch ex As System.UriFormatException Return End Try End Sub
Updates the URL in textbox upon navigation
Private Sub webBrowser1_Navigated(ByVal sender As Object, _ ByVal e As WebBrowserNavigatedEventArgs) _ Handles WebBrowser1.Navigated textBoxURL.Text = WebBrowser1.Url.ToString() End Sub