我有一个标签式浏览器,并在表单后面放置一个webbrowser,因此它不会在设计或代码中显示,也无法调用:Private Sub WebBrowser1_NewWindow(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles WebBrowser1.NewWindow
这是我加载表单的方式:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Dim tab As New TabPage
Dim brws As New WebBrowser
brws.ScriptErrorsSuppressed = True
brws.Dock = DockStyle.Fill
tab.Text = " New Tab"
tab.Controls.Add(brws)
Me.TabControl1.TabPages.Add(tab)
Me.TabControl1.SelectedTab = tab
brws.Navigate("")
Catch ex As Exception
End Try
End Sub
如何从标签式浏览器中捕获新窗口?我需要它来加载传出/外部链接以在新窗口中打开而不是在IE中打开。
我试过这个但是什么都不做:
Private Sub WebBrowserNewWindow(ByVal sender As Object, ByVal e As System.EventArgs)
MsgBox("catched the new window")
End Sub
答案 0 :(得分:1)
您需要添加该行(创建控件后):
AddHandler brws.NewWindow, AddressOf WebBrowserNewWindow
要处理该事件,请参阅http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.newwindow(v=vs.110).aspx