用VB制作自己的IE网页浏览器
2011年04月23日
1、在工具箱中添加“Microsoft Internet Controls”控件;
“microsoft common dialog control 6.0”控件;
“Microsoft Windows Common Control”控件;
2、在Form1窗口中添加添加1个ComboBox控件,5个CommandButton控件,
1个Common Dialpg控件,1个WebBrowser控件;
1个StatusBar控件和1个ProgressBar控件。
如图所示:
http://b63.photo.store.qq.com/http_imgload.cgi?/rurl4_b=e64038147f12951908f2522c130c4b8faf3f009dc31e83519b14dc80c05d50f214adba8fbcd4b09a7a6e4202a3489409a7f9aee1717e4aa893b2f05c0e0d899a0328563e19869fe9c9e4c14fe7cf05994bbe399b&a=63&b=63
3、双击Form1窗口,输入下列代码:
Option Explicit
Private Sub Combo1_Click()
WebBrowser1.Navigate Combo1.Text ' 打开指定网址
End Sub
Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
Dim I As Long
Dim existed As Boolean
If KeyCode = 13 Then
If Left(Combo1.Text, 7) "http://" Then '如果输入网址不是以“http://”开头则自动添加
Combo1.Text = "http://" + Combo1.Text + ".com"
End If
WebBrowser1.Navigate Combo1.Text ' URL地址栏保存的网站地址
For I = 0 To Combo1.ListCount - 1
If Combo1.List(I) = Combo1.Text Then
existed = True
Exit For
Else
existed = False
End If
Next
If Not existed Then
Combo1.AddItem (Combo1.Text) ' 如果输入新的网站则自动保存
End If
End If
End Sub
Private Sub Command1_Click()
WebBrowser1.GoSearch
End Sub
Private Sub Command2_Click()
WebBrowser1.GoForward
End Sub
Private Sub Command3_Click()
WebBrowser1.GoBack
End Sub
Private Sub Command4_Click()
WebBrowser1.Stop
End Sub
Private Sub Command5_Click()
WebBrowser1.Refresh
End Sub
Private Sub Command6_Click()
CommonDialog1.ShowOpen '激活打开文件对话框选择文件
WebBrowser1.Navigate CommonDialog1.FileName
WebBrowser1.Stop
End Sub
Private Sub Form_Load()
Combo1.Text = ""
Combo1.AddItem "http://www.baidu.com/"
Combo1.AddItem "http://www.sina.com.cn/"
Combo1.AddItem "http://user.qzone.qq.com/925519388/ "
Combo1.Top = 0 + 40 ' 设置URL地址栏起始位置
Combo1.Left = 0
WebBrowser1.Top = Combo1.Top + Combo1.Height + 40 ' 设置页面浏览区位置
WebBrowser1.Left = 0
Form_Resize
StatusBar1.Style = sbrSimple
ProgressBar1.ZOrder
WebBrowser1.GoHome
End Sub
Private Sub Form_Resize()
On Error GoTo a
Combo1.Width = Form1.Width - 5150 ' URL地址栏宽度随窗口大小调整而变化
WebBrowser1.Width = Form1.Width - 100
WebBrowser1.Height = Form1.Height - Combo1.Height - 1000 ' 浏览器高度随窗口大小调整而变化
ProgressBar1.Top = Me.Height - StatusBar1.Height - 330 ' 进程
ProgressBar1.Left = 0.25 * StatusBar1.Width
ProgressBar1.Width = 0.75 * Me.Width - 250
Command1.Left = Form1.Width - 5100
Command2.Left = Form1.Width - 4300
Command3.Left = Form1.Width - 3700
Command4.Left = Form1.Width - 3100
Command5.Left = Form1.Width - 2500
Command6.Left = Form1.Width - 1800 '设置6个Command按钮水平位置随窗口大小调整而变化
a:
End Sub
Private Sub WebBrowser1_DownloadComplete()
StatusBar1.SimpleText = "下载完成" '下载完成时状态栏显示“下载完成”
ProgressBar1.Value = 0
End Sub
Private Sub WebBrowser1_ProgressChange(ByVal Progress As Long, ByVal ProgressMax As Long)
If ProgressMax = 0 Then Exit Sub '下载进行时进度条变化
ProgressBar1.Max = ProgressMax
If Progress -1 And Progress <= ProgressMax Then
ProgressBar1.Value = Progress
End If
End Sub
Private Sub WebBrowser1_TitleChange(ByVal Text As String)
Combo1.Text = WebBrowser1.LocationURL
End Sub
浏览效果图:
http://b63.photo.store.qq.com/http_imgload.cgi?/rurl4_b=e64038147f12951908f2522c130c4b8fe2332b82ccb28f3706c8ccf96217a26c6baf6f73fd24a0a5defc05ae95f05250d6caceeac30b2f7876b6ac0ae53bcb1848816d91f1e59a537fa5f0383584d78a5d178759&a=63&b=63
2011年04月23日
1、在工具箱中添加“Microsoft Internet Controls”控件;
“microsoft common dialog control 6.0”控件;
“Microsoft Windows Common Control”控件;
2、在Form1窗口中添加添加1个ComboBox控件,5个CommandButton控件,
1个Common Dialpg控件,1个WebBrowser控件;
1个StatusBar控件和1个ProgressBar控件。
如图所示:
http://b63.photo.store.qq.com/http_imgload.cgi?/rurl4_b=e64038147f12951908f2522c130c4b8faf3f009dc31e83519b14dc80c05d50f214adba8fbcd4b09a7a6e4202a3489409a7f9aee1717e4aa893b2f05c0e0d899a0328563e19869fe9c9e4c14fe7cf05994bbe399b&a=63&b=63
3、双击Form1窗口,输入下列代码:
Option Explicit
Private Sub Combo1_Click()
WebBrowser1.Navigate Combo1.Text ' 打开指定网址
End Sub
Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
Dim I As Long
Dim existed As Boolean
If KeyCode = 13 Then
If Left(Combo1.Text, 7) "http://" Then '如果输入网址不是以“http://”开头则自动添加
Combo1.Text = "http://" + Combo1.Text + ".com"
End If
WebBrowser1.Navigate Combo1.Text ' URL地址栏保存的网站地址
For I = 0 To Combo1.ListCount - 1
If Combo1.List(I) = Combo1.Text Then
existed = True
Exit For
Else
existed = False
End If
Next
If Not existed Then
Combo1.AddItem (Combo1.Text) ' 如果输入新的网站则自动保存
End If
End If
End Sub
Private Sub Command1_Click()
WebBrowser1.GoSearch
End Sub
Private Sub Command2_Click()
WebBrowser1.GoForward
End Sub
Private Sub Command3_Click()
WebBrowser1.GoBack
End Sub
Private Sub Command4_Click()
WebBrowser1.Stop
End Sub
Private Sub Command5_Click()
WebBrowser1.Refresh
End Sub
Private Sub Command6_Click()
CommonDialog1.ShowOpen '激活打开文件对话框选择文件
WebBrowser1.Navigate CommonDialog1.FileName
WebBrowser1.Stop
End Sub
Private Sub Form_Load()
Combo1.Text = ""
Combo1.AddItem "http://www.baidu.com/"
Combo1.AddItem "http://www.sina.com.cn/"
Combo1.AddItem "http://user.qzone.qq.com/925519388/ "
Combo1.Top = 0 + 40 ' 设置URL地址栏起始位置
Combo1.Left = 0
WebBrowser1.Top = Combo1.Top + Combo1.Height + 40 ' 设置页面浏览区位置
WebBrowser1.Left = 0
Form_Resize
StatusBar1.Style = sbrSimple
ProgressBar1.ZOrder
WebBrowser1.GoHome
End Sub
Private Sub Form_Resize()
On Error GoTo a
Combo1.Width = Form1.Width - 5150 ' URL地址栏宽度随窗口大小调整而变化
WebBrowser1.Width = Form1.Width - 100
WebBrowser1.Height = Form1.Height - Combo1.Height - 1000 ' 浏览器高度随窗口大小调整而变化
ProgressBar1.Top = Me.Height - StatusBar1.Height - 330 ' 进程
ProgressBar1.Left = 0.25 * StatusBar1.Width
ProgressBar1.Width = 0.75 * Me.Width - 250
Command1.Left = Form1.Width - 5100
Command2.Left = Form1.Width - 4300
Command3.Left = Form1.Width - 3700
Command4.Left = Form1.Width - 3100
Command5.Left = Form1.Width - 2500
Command6.Left = Form1.Width - 1800 '设置6个Command按钮水平位置随窗口大小调整而变化
a:
End Sub
Private Sub WebBrowser1_DownloadComplete()
StatusBar1.SimpleText = "下载完成" '下载完成时状态栏显示“下载完成”
ProgressBar1.Value = 0
End Sub
Private Sub WebBrowser1_ProgressChange(ByVal Progress As Long, ByVal ProgressMax As Long)
If ProgressMax = 0 Then Exit Sub '下载进行时进度条变化
ProgressBar1.Max = ProgressMax
If Progress -1 And Progress <= ProgressMax Then
ProgressBar1.Value = Progress
End If
End Sub
Private Sub WebBrowser1_TitleChange(ByVal Text As String)
Combo1.Text = WebBrowser1.LocationURL
End Sub
浏览效果图:
http://b63.photo.store.qq.com/http_imgload.cgi?/rurl4_b=e64038147f12951908f2522c130c4b8fe2332b82ccb28f3706c8ccf96217a26c6baf6f73fd24a0a5defc05ae95f05250d6caceeac30b2f7876b6ac0ae53bcb1848816d91f1e59a537fa5f0383584d78a5d178759&a=63&b=63