程序的主角是一个ActiveX控件:Webbrowser。当然,缺省状态下VB的工具箱中并没有它,我们得手工加入,方法是:右击工具箱,在出现的快捷菜单中选择“部件...”,确保在d出的对话框中选中“控件”标签,找到Microsoft Internet Controls,在它前面的小框中打钩,然后确定。此时你会发现工具箱中多了两个小图标,其中,地球图标代表的控件正是我们需要的Webbrowser。
由于许多人对Webbrowser控件不是很熟悉,VB的帮助中也没有有关它的内容(反正我没有找到),因此有必要介绍一下它的属性、方法和事件,限于篇幅,我们只涉及程序中用到的:
属性:LocationURL 返回控件显示WEB页面的URL。
方法:Navigate 转移到指定的URL或打开指定HTML文件。
事件:1.DownloadBegin 下载 *** 作开时触发。
2.DownloadComplete 下载 *** 作完成、终止或失败时触发。
3.ProgressChange Webbrowser控件跟踪下载 *** 作的过程,并定期触发此事件。其语法为:Sub Webbrowser_ProgressChange (ByVal Progress As Long,ByVal ProgressMax As Long)。Progress变元是当前已下载的数据总量,ProgressMax变元是将要下载的数据总量。
4.TitleChange 当前文档标题改变时触发
除了Webbrowser控件外,程序还需要一个Label控件:Label1;一个Combo@R_419_6951@控件:combo1,用来显示URL地址;一个Statusbar控件:Statusbar1;一个Progressbar控件:Progressbar1,用来显示下载进度(Statusbar控件和Progressbar控件是ActiveX控件Microsoft windows Common Controls5.0的成员,加入工具箱的方法同Webbrowser控件),这些控件的属性值都用缺省值。
以下是程序清单:
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,Shift 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 |
以上是内存溢出为你收集整理的自己的IE——用VB制作浏览器DIY全部内容,希望文章能够帮你解决自己的IE——用VB制作浏览器DIY所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)