William Taylor William Taylor - 1 month ago 5
Vb.net Question

How To Navigate WebBrowser 2 When WebBrowser 1 URL Changed

I am currently making a VB.Net application for a computer with 2 touch screens. Both of the screens are going to have a Web Browser on them. When I click a link on WebBrowser 1, what I want to happen is for the second WebBrowser(on the other screen) to actually navigate to this URL, and the original WebBrowser to keep the original page it is on.

Help would be appreciated!

Thanks

Answer

Use the Navigating event to cancel navigation and send the url to the other browser.

Private mFirstLoadComplete As Boolean = False

Private Sub Form5_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    WebBrowser1.Navigate("www.stackoverflow.com")
End Sub

Private Sub WebBrowser1_Navigated(sender As Object, e As System.Windows.Forms.WebBrowserNavigatedEventArgs) Handles WebBrowser1.Navigated
    mFirstLoadComplete = True
End Sub

Private Sub WebBrowser1_Navigating(sender As Object, e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating
    If Not mFirstLoadComplete Then Return
    e.Cancel = True
    WebBrowser2.Navigate(e.Url)
End Sub
Comments