VB制作精简的IE浏览器
VB制作精简的IE浏览器
2011年04月28日
Option Explicit
‘变量声明
’strURL,字符型
Dim strURL As String Private Sub Form_Load()
‘设为True的作用是当网页出现脚本错误时不提示
WebBrowser1.Silent = True
‘在这里输入网页地址,在这里我随便改一个可用的地址便于测试
WebBrowser1.Navigate “http://www.hao123.com”
‘这是窗体名称的更新频率
Timer1.Interval = 500
End Sub
‘让所有链接都用这个浏览器打开
Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)
Cancel = True
WebBrowser1.Navigate strURL
End Sub
Private Sub WebBrowser1_StatusTextChange(ByVal Text As String)
strURL = Text
End Sub
‘当窗体大小改变时,使WebBrowser1控件大小填满整个窗口
Private Sub Form_Resize()
On Error Resume Next
WebBrowser1.Width = Me.Width - 100
WebBrowser1.Height = Me.Height - 450
End Sub
‘结束
Private Sub Form_Unload(Cancel As Integer)
End
End Sub
‘利用Timer来更新窗体标题
Private Sub Timer1_Timer()
Me.Caption = WebBrowser1.LocationName
Timer1.Enabled = True
End Sub
另外一种方法:
Option Explicit
'strURL,字符型
Dim strURL As String
Private Sub WebBrowser1_NewWindow2(ppDisp As Object, Cancel As Boolean)
Dim NFrm As New Form1
NFrm.WebBrowser1.RegisterAsBrowser = True
Set ppDisp = NFrm.WebBrowser1.Object
NFrm.Visible = True
End Sub
Private Sub WebBrowser1_StatusTextChange(ByVal Text As String)
strURL = Text
End Sub
Private Sub Form_Resize()
On Error Resume Next
WebBrowser1.Width = Me.Width - 100
WebBrowser1.Height = Me.Height - 450
End Sub
Private Sub Form_Unload(Cancel As Integer)
End
End Sub
Private Sub Timer1_Timer()
Me.Caption = WebBrowser1.LocationName
Timer1.Enabled = True
End Sub
Private Sub Form_Load()
WebBrowser1.Navigate "http://tv.sohu.com/hdtv/"
End Sub