用VB制作自己的IE网页浏览器
生活随笔
收集整理的這篇文章主要介紹了
用VB制作自己的IE网页浏览器
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
用VB制作自己的IE網(wǎng)頁瀏覽器
2011年04月23日
1、在工具箱中添加“Microsoft Internet Controls”控件;
“microsoft common dialog control 6.0”控件;
“Microsoft Windows Common Control”控件;
2、在Form1窗口中添加添加1個(gè)ComboBox控件,5個(gè)CommandButton控件,
1個(gè)Common Dialpg控件,1個(gè)WebBrowser控件;
1個(gè)StatusBar控件和1個(gè)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 ' 打開指定網(wǎng)址
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 '如果輸入網(wǎng)址不是以“http://”開頭則自動添加
Combo1.Text = "http://" + Combo1.Text + ".com"
End If
WebBrowser1.Navigate Combo1.Text ' URL地址欄保存的網(wǎng)站地址
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) ' 如果輸入新的網(wǎng)站則自動保存
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 ' 設(shè)置URL地址欄起始位置
Combo1.Left = 0
WebBrowser1.Top = Combo1.Top + Combo1.Height + 40 ' 設(shè)置頁面瀏覽區(qū)位置
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地址欄寬度隨窗口大小調(diào)整而變化
WebBrowser1.Width = Form1.Width - 100
WebBrowser1.Height = Form1.Height - Combo1.Height - 1000 ' 瀏覽器高度隨窗口大小調(diào)整而變化
ProgressBar1.Top = Me.Height - StatusBar1.Height - 330 ' 進(jìn)程
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 '設(shè)置6個(gè)Command按鈕水平位置隨窗口大小調(diào)整而變化
a:
End Sub
Private Sub WebBrowser1_DownloadComplete()
StatusBar1.SimpleText = "下載完成" '下載完成時(shí)狀態(tài)欄顯示“下載完成”
ProgressBar1.Value = 0
End Sub
Private Sub WebBrowser1_ProgressChange(ByVal Progress As Long, ByVal ProgressMax As Long)
If ProgressMax = 0 Then Exit Sub '下載進(jìn)行時(shí)進(jìn)度條變化
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個(gè)ComboBox控件,5個(gè)CommandButton控件,
1個(gè)Common Dialpg控件,1個(gè)WebBrowser控件;
1個(gè)StatusBar控件和1個(gè)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 ' 打開指定網(wǎng)址
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 '如果輸入網(wǎng)址不是以“http://”開頭則自動添加
Combo1.Text = "http://" + Combo1.Text + ".com"
End If
WebBrowser1.Navigate Combo1.Text ' URL地址欄保存的網(wǎng)站地址
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) ' 如果輸入新的網(wǎng)站則自動保存
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 ' 設(shè)置URL地址欄起始位置
Combo1.Left = 0
WebBrowser1.Top = Combo1.Top + Combo1.Height + 40 ' 設(shè)置頁面瀏覽區(qū)位置
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地址欄寬度隨窗口大小調(diào)整而變化
WebBrowser1.Width = Form1.Width - 100
WebBrowser1.Height = Form1.Height - Combo1.Height - 1000 ' 瀏覽器高度隨窗口大小調(diào)整而變化
ProgressBar1.Top = Me.Height - StatusBar1.Height - 330 ' 進(jìn)程
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 '設(shè)置6個(gè)Command按鈕水平位置隨窗口大小調(diào)整而變化
a:
End Sub
Private Sub WebBrowser1_DownloadComplete()
StatusBar1.SimpleText = "下載完成" '下載完成時(shí)狀態(tài)欄顯示“下載完成”
ProgressBar1.Value = 0
End Sub
Private Sub WebBrowser1_ProgressChange(ByVal Progress As Long, ByVal ProgressMax As Long)
If ProgressMax = 0 Then Exit Sub '下載進(jìn)行時(shí)進(jìn)度條變化
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
總結(jié)
以上是生活随笔為你收集整理的用VB制作自己的IE网页浏览器的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 大型网站架构:Flickr网站体系结构分
- 下一篇: 联想ThinkPad升级BIOS和EC新