Option Strict On
Option Explicit On
Public Class Form1
Declare the webbrowser and a url string
Private browser As WebBrowser
Private urlString As String = "http://stackoverflow.com/questions/ask"
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Calls the sub "newTab"
newTab()
End Sub
Private Sub newTab()
'Creates a new instance of the webbrowser
browser = New WebBrowser
'Sets the webbrowser's properties
With browser
.Navigate(urlString)
.Dock = DockStyle.Fill
End With
'Declare a new tabpage and add it to the tabcontrol
Dim tp As New TabPage("New Tab")
TabControl1.Controls.Add(tp)
'Add the webbrowser to the tabpage
tp.Controls.Add(browser)
'Create a new instance of the NewWindow for the new webbrowser
AddHandler browser.NewWindow, AddressOf BrowserNewWindow
End Sub
Private Sub BrowserNewWindow(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
'Stops the new window
e.Cancel = True
Dim element As HtmlElement = Browser.Document.ActiveElement
Dim url As String = element.GetAttribute("href")
urlString = url
'Calls the sub "newTab"
newTab()
End Sub
End Class
您好,请帮我修改我的程序我猜我的问题很简单。当我点击tabcontrol1内的链接时,新的标签链接在我点击它停留在第一页后没有自动重定向。
任何帮助都会受到欢迎!