彩票走势图

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

转帖|其它|编辑:郝浩|2008-09-24 11:43:28.000|阅读 3095 次

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

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

操作步骤:

1、在工程中添加COM的Microsoft Internet Controls的引用(这个引用对应的文件是shdocvw.dll,通常在system32目录下)。

2、如下代码:

Public Class Form1Class Form1
    Private Sub NewWindow3()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
    End Sub


    Private Sub NewWindow2()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
    End Sub


    Private Sub Form1_Load()Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '在窗体载入后设置Webbrowser的NewWindow3事件处理函数
        'AddHandler DirectCast(WebBrowser1.ActiveXInstance, SHDocVw.WebBrowser).NewWindow3, AddressOf NewWindow3
        '如果不是Windows XP SP2的话需要监控NewWindow2消息
        AddHandler DirectCast(WebBrowser1.ActiveXInstance, SHDocVw.WebBrowser).NewWindow2, AddressOf NewWindow2

        WebBrowser1.Navigate("//www.applevb.com")
    End Sub

End Class

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


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn

文章转载自:个人博客

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP