操作步骤: 1、在工程中添加COM的Microsoft Internet Controls的引用(这个引用对应的文件是shdocvw.dll,通常在system32目录下)。 2、如下代码:
Public
ClassForm1
Class Form1 Private SubNewWindow3() Sub NewWindow3( ByRef ppDisp As Object , ByRef Cancel As Boolean ,_ ByVal dwFlags As UInteger ,_ ByVal bstrUrlContext As String , ByVal bstrUrl As String ) Dim xPage As TabPage = New TabPage xPage.Text = " abcd " TabControl1.TabPages.Add(xPage)Dim x As New WebBrowser DirectCast (WebBrowser1.ActiveXInstance,SHDocVw.WebBrowser).RegisterAsBrowser = True xPage.Controls.Add(x) x.Dock= DockStyle.Fill x.Visible = True x.Navigate(bstrUrl) Cancel= True EndSub Private SubNewWindow2() Sub NewWindow2( ByRef ppDisp As Object , ByRef Cancel As Boolean ) Dim xPage As TabPage = New TabPage xPage.Text = " abcd " TabControl1.TabPages.Add(xPage)Dim x As New WebBrowser DirectCast (WebBrowser1.ActiveXInstance,SHDocVw.WebBrowser).RegisterAsBrowser = True xPage.Controls.Add(x) x.Dock= DockStyle.Fill x.Visible = True x.Navigate(" about:blank " ) ppDisp = x.ActiveXInstance ' DirectCast(x.ActiveXInstance,SHDocVw.WebBrowser).Application ' Cancel=True EndSub Private SubForm1_Load() Sub Form1_Load( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase .Load ' 在窗体载入后设置Webbrowser的NewWindow3事件处理函数 ' AddHandlerDirectCast(WebBrowser1.ActiveXInstance,SHDocVw.WebBrowser).NewWindow3,AddressOfNewWindow3 ' 如果不是WindowsXPSP2的话需要监控NewWindow2消息 AddHandler DirectCast (WebBrowser1.ActiveXInstance,SHDocVw.WebBrowser).NewWindow2, AddressOf NewWindow2 WebBrowser1.Navigate( " http://www.applevb.com " ) EndSub EndClass
运行程序,可以看到新打开的窗口都会在TabControl1的新标签页abcd中打开.