在VB.NET中如何使在Webbrowser中实现标签页中打开新链接

操作步骤:
1、在工程中添加COM的Microsoft Internet Controls的引用(这个引用对应的文件是shdocvw.dll,通常在system32目录下)。
2、如下代码:


Public ClassForm1 ClassForm1
PrivateSubNewWindow3()SubNewWindow3(ByRefppDispAsObject,ByRefCancelAsBoolean,_
ByValdwFlagsAsUInteger,_
ByValbstrUrlContextAsString,ByValbstrUrlAsString)

DimxPageAsTabPage=NewTabPage
xPage.Text
="abcd"
TabControl1.TabPages.Add(xPage)

DimxAsNewWebBrowser
DirectCast(WebBrowser1.ActiveXInstance,SHDocVw.WebBrowser).RegisterAsBrowser=True

xPage.Controls.Add(x)
x.Dock
=DockStyle.Fill
x.Visible
=True

x.Navigate(bstrUrl)
Cancel
=True
EndSub



PrivateSubNewWindow2()SubNewWindow2(ByRefppDispAsObject,ByRefCancelAsBoolean)
DimxPageAsTabPage=NewTabPage
xPage.Text
="abcd"
TabControl1.TabPages.Add(xPage)

DimxAsNewWebBrowser
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



PrivateSubForm1_Load()SubForm1_Load(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesMyBase.Load
'在窗体载入后设置Webbrowser的NewWindow3事件处理函数
'AddHandlerDirectCast(WebBrowser1.ActiveXInstance,SHDocVw.WebBrowser).NewWindow3,AddressOfNewWindow3
'如果不是WindowsXPSP2的话需要监控NewWindow2消息
AddHandlerDirectCast(WebBrowser1.ActiveXInstance,SHDocVw.WebBrowser).NewWindow2,AddressOfNewWindow2

WebBrowser1.Navigate(
"http://www.applevb.com")
EndSub


EndClass


运行程序,可以看到新打开的窗口都会在TabControl1的新标签页abcd中打开.

你可能感兴趣的:(.net,Microsoft,vb,VB.NET)