如何使文本框显示Web浏览器当前所在网页的URL?

时间:2019-01-06 09:15:02

标签: vb.net webbrowser-control

我希望TextBox显示Web浏览器当前所在的网页的URL。下面显示的代码似乎无法解决我的问题。

通过调用TextBox导航到上一页时,WebBrowser1.GoBack()不会改变

衷心感谢您的帮助!

我已经尝试过了:

Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
  TextBox1.Text = WebBrowser1.Url.ToString()
End Sub

1 个答案:

答案 0 :(得分:1)

使用WebBrowser的Navigated事件获取其当前URL。

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    WebBrowser1.GoBack()
End Sub

Private Sub WebBrowser1_Navigated(sender As Object, e As WebBrowserNavigatedEventArgs) Handles WebBrowser1.Navigated
    TextBox1.Text = e.Url.ToString
End Sub