初步完成:
1.在本程序打开链接,不会转到IE那里,不乱弹窗口
2.多个选项卡同时浏览不同页面
Imports System.Threading
Public Class Form1
Dim 地址框 As TextBox
Friend WithEvents Button进入 As Button
Friend WithEvents Button辅助 As Button
Friend WithEvents Button收藏 As Button
Friend WithEvents Button新选项卡 As Button
Friend WithEvents 我的选项卡 As 选项卡
Friend WithEvents 选项卡首页 As 选项卡页
Friend WithEvents 首页浏览窗口 As 浏览窗口
Dim 地址
Private Sub form1_load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call Form设计()
地址 = New Uri(Me.地址框.Text)
End Sub
Sub Form设计()
Me.Text = "页游浏览器"
地址框 = New TextBox()
Button进入 = New Button()
Button辅助 = New Button()
Button收藏 = New Button()
Button新选项卡 = New Button()
Me.Controls.Add(地址框)
Me.Controls.Add(Button进入)
Me.Controls.Add(Button辅助)
Me.Controls.Add(Button收藏)
Me.Controls.Add(Button新选项卡)
我的选项卡 = New 选项卡()
Me.Controls.Add(我的选项卡)
选项卡首页 = New 选项卡页()
我的选项卡.Controls.Add(选项卡首页)
首页浏览窗口 = New 浏览窗口()
选项卡首页.Controls.Add(首页浏览窗口)
首页浏览窗口.Url = New System.Uri("
https://tieba.baidu.com/f?kw=vb.net", System.UriKind.Absolute)
Me.WindowState = 2
Dim 首行高度 As Integer = Me.Font.Height + 8
Dim 导航按钮宽度 As Integer = 80
With 地址框
.Location = New System.Drawing.Point(3, 0)
.Size = New System.Drawing.Size(400, 首行高度)
.TabIndex = 1
.Text = "
http://www.baidu.com"
End With
With Button进入
.Location = New System.Drawing.Point(地址框.Width + 3, 0)
.Size = New System.Drawing.Size(导航按钮宽度, 首行高度)
.TabIndex = 2
.Text = "进入"
End With
With Button辅助
.Location = New System.Drawing.Point(地址框.Width + 3 + 导航按钮宽度, 0)
.Size = New System.Drawing.Size(导航按钮宽度, 首行高度)
.TabIndex = 3
.Text = "辅助"
End With
With Button收藏
.Location = New System.Drawing.Point(地址框.Width + 3 + 导航按钮宽度 * 2, 0)
.Size = New System.Drawing.Size(导航按钮宽度, 首行高度)
.TabIndex = 3
.Text = "收藏"
End With
With Button新选项卡
.Location = New System.Drawing.Point(地址框.Width + 3 + 导航按钮宽度 * 3, 0)
.Size = New System.Drawing.Size(导航按钮宽度, 首行高度)
.TabIndex = 5
.Text = "新选项卡"
End With
With 我的选项卡
.TabIndex = 4
.RightToLeft = System.Windows.Forms.RightToLeft.Yes
.RightToLeftLayout = True
.Dock = DockStyle.Fill
End With
With 首页浏览窗口
.Dock = DockStyle.Fill
End With
End Sub
Class 选项卡
Inherits System.Windows.Forms.TabControl
End Class
Class 选项卡页
Inherits System.Windows.Forms.TabPage
'重写一些东东
End Class
Class 浏览窗口
Inherits System.Windows.Forms.WebBrowser
Protected Sub 浏览窗口_Navigating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyClass.Navigating
MyBase.ScriptErrorsSuppressed = True
End Sub
Protected Sub 浏览窗口_Navigated(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserNavigatedEventArgs) Handles MyClass.Navigated
Form1.地址框.Text = Me.Url.ToString
End Sub
Protected Sub 浏览窗口_NewWindow(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyClass.NewWindow
e.Cancel = True
Dim urlNew = sender.Document.ActiveElement.GetAttribute("href")
MyBase.ScriptErrorsSuppressed = True
MyBase.Navigate(urlNew)
End Sub
End Class
Private Sub Button进入_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button进入.Click
地址 = New Uri(地址框.Text)
首页浏览窗口.Navigate(地址)
End Sub
Private Sub Button新选项卡_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button新选项卡.Click
Dim 新选项卡 As 选项卡页 = New 选项卡页()
我的选项卡.Controls.Add(新选项卡)
Dim 新浏览窗口 = New 浏览窗口()
新选项卡.Controls.Add(新浏览窗口)
新浏览窗口.Url = New System.Uri("
http://www.baidu.com", System.UriKind.Absolute)
新浏览窗口.Dock = DockStyle.Fill
End Sub
End Class