我有Form1
button1
和webbrowser1
。当我点击button1
时,我想以相同的形式打开新的网络浏览器标签,而不是在Firefox或Internet Explorer或Chrome中。
我尝试使用TabControl,但我不确定它是如何工作的,因为它没有调整大小和它的烦恼。我只想在表单中使用Web浏览器打开一个新选项卡。
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
答案 0 :(得分:1)
要添加新的标签式浏览器,首先需要在现有的 TabControl 中添加新的标签, 添加新的标签后,您需要在创建的标签
中添加新的浏览器控件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
答案 1 :(得分: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
答案 2 :(得分: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