1

我有一个Form1withbutton1和一个webbrowser1. 当我单击 时button1,我想以相同的形式打开一个新的 Web 浏览器选项卡,而不是在 Firefox、Internet Explorer 或 Chrome 中。

我尝试使用 TabControl,但不确定它是如何工作的,因为它不会调整大小并且有点烦人。我只想在表单中使用网络浏览器打开一个新选项卡。

Public Class Form1
  Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim wb As New WebBrowser
    wb.Navigate("www.google.com")
    Dim tab As New TabPage("Title")
    tab.Controls.Add(wb)
    TabControl1.TabPages.Add(tab)
    TabControl1.SelectedTab = tab
    tab.Size = New System.Drawing.Size(280, 174)
  End Sub
End Class
4

3 回答 3

1

要添加一个新的 Tabbed 浏览器,首先你需要在现有的TabControl中添加一个新的Tab,一旦添加了新的Tab,然后你需要在创建的Tab中添加一个新的浏览器控件

Private Sub btnAddTab_Click(sender As Object, e As EventArgs)
    Dim page As New TabPage(String.Format("Tab # {0}", tabControl1.TabPages.Count + 1))
    tabControl1.TabPages.Add(page)
    Dim browser As New WebBrowser()
    page.Controls.Add(browser)
    browser.Dock = DockStyle.Fill
    browser.Navigate(New Uri("http://www.google.co.in"))

End Sub
于 2013-01-19T05:34:51.403 回答
0

创建您自己的TabPage,以便您可以轻松处理事件和控件:

Public Class WBTab
    Inherits TabPage 'it actually is a tabpage
    Public WithEvents WB As New WebBrowser 'that has a single webbrowser in it
    Sub New(ByVal URL As String) 'when the page is created, show it and load the URL
        WB.Dock = DockStyle.Fill
        Me.Controls.Add(WB)
        WB.Navigate(URL)
    End Sub

    Private Sub WebBrowser1_DocumentCompleted(sender As System.Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WB.DocumentCompleted
        Me.Text = WB.DocumentTitle 'when the page is loaded you may now show its title in your tab.
    End Sub

    Private Sub WB_Navigating(sender As Object, e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Handles WB.Navigating
        Me.Text = e.Url.ToString
    End Sub
End Class

现在可以使用了:

Dim google As New WBTab("google.com") 'create a new tab with URL
TabControl1.TabPages.Add(google) 'show it
于 2013-01-19T05:47:28.650 回答
0

这应该有效:

 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Dim tabpage As New TabPage
    tabpage.Text = "New Tab"

    TabControl1.TabPages.Add(tabpage)

    Dim webBrowser As New WebBrowser
    TabControl1.SelectedTab = tabpage
    tabpage.Controls.Add(webBrowser)
    webBrowser.Dock = DockStyle.Fill
    webBrowser.Navigate("http://www.stackoverflow.com")
End Sub
于 2013-01-19T05:49:44.793 回答