专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »VB教程 » vb制作浏览器:用VB制作浏览器 »正文

vb制作浏览器:用VB制作浏览器

来源: 发布时间:星期四, 2009年2月12日 浏览:125次 评论:0


自己做浏览器?有没有搞错?不要说像IE这样庞然大物就是小巧Opera我们大多数普通人也决计搞不出来但如果你机器里装有VB5.0专业版那么事情就好办多了想试试吗?那好Let`s go!
  主角是个ActiveXControl控件:WebBrowser当然缺省状态下VB工具箱中并没有它我们得手工加入思路方法是:右击工具箱在出现快捷菜单中选择“部件...”确保在弹出对话框中选中“Control控件”标签找到Microsoft Internet Controls在它前面小框中打钩然后确定此时你会发现工具箱中多了两个小图标其中地球图标代表Control控件正是我们需要WebBrowser
  由于许多人对WebBrowserControl控件不是很熟悉VB帮助中也没有有关它内容(反正我没有找到)因此有必要介绍下它属性、思路方法和事件限于篇幅我们只涉及中用到:
  属性:LocationURL 返回Control控件显示WEB页面URL
  思路方法:Navigate 转移到指定URL或打开指定HTML文件
  事件:1.DownloadBegin 下载操作开时触发
  2.DownloadComplete 下载操作完成、终止或失败时触发
  3.ProgressChange WebBrowserControl控件跟踪下载操作过程并定期触发此事件其语法为:Sub WebBrowser_ProgressChange (ByVal Progress As Long, ByVal ProgressMax As Long)Progress变元是当前已下载数据总量ProgressMax变元是将要下载数据总量
  4.TitleChange 当前文档标题改变时触发
  除了WebBrowserControl控件外还需要个LabelControl控件:Label1;个ComboBoxControl控件:combo1用来显示URL地址;个StatusBarControl控件:StatusBar1;个ProgressBarControl控件:ProgressBar1用来显示下载进度(StatusBarControl控件和ProgressBarControl控件是ActiveXControl控件Microsoft Windows Common Controls5.0成员加入工具箱思路方法同WebBrowserControl控件)这些Control控件属性值都用缺省值
  以下是清单:
  Option Explicit
  
  Private Sub Form_Load
  Me.Caption =“My Explorer”
  Label1.Caption = “URL”
  Combo1.Text = “”
  Combo1.Top = Label1.Height
  Combo1.Left = 0
  WebBrowser1.Top = Combo1.Top + Combo1.Height
  WebBrowser1.Left = 0
  Form_Resize
  StatusBar1.Style = sbrSimple
  ProgressBar1.Zorder
  End Sub
  
  Private Sub Form_Resize
  On Error GoTo a
  Combo1.Width = Form1.Width - 100
  WebBrowser1.Width = Combo1.Width
  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
  a:
  End Sub
  
  Private Sub Combo1_Click
  `转到指定网址
  WebBrowser1.Navigate Combo1.Text
  End Sub
  
  Private Sub Combo1_KeyDown(KeyCode As Integer, Sht As Integer)
  Dim I As Long
  Dim existed As Boolean
  If KeyCode = 13 Then
  If Left(Combo1.Text, 7) <> “http://”Then
  Combo1.Text = “http://”+ Combo1.Text
  End If
  WebBrowser1.Navigate Combo1.Text
  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 WebBrowser1_DownloadBegin
  `下载开始时状态栏显示“Now Linking...”
  StatusBar1.SimpleText = “Now Linking...”
  End Sub
  
  Private Sub WebBrowser1_DownloadComplete
  `下载完成时状态栏显示“Link Finished”
  StatusBar1.SimpleText = “Link Finished”
  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
0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: