如何在WebBrowser 1 URL更改时导航WebBrowser 2

时间:2016-10-25 08:53:11

标签: .net vb.net webbrowser-control

我目前正在为具有2个触摸屏的计算机制作VB.Net应用程序。两个屏幕都将有一个Web浏览器。当我单击WebBrowser 1上的链接时,我想要发生的是第二个WebBrowser(在另一个屏幕上)实际导航到此URL,以及原始WebBrowser以保持其所在的原始页面。

帮助将不胜感激!

由于

1 个答案:

答案 0 :(得分:1)

使用Navigating事件取消导航并将网址发送到其他浏览器。

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