自己的IE——用VB制作浏览器
[入库:2005年8月18日] [更新:2007年3月24日]
|
自己的ie——用vb制作浏览器 |
|
作者:钱可栋 |
|
|
自己做浏览器?有没有搞错?不要说像ie这样的庞然大物,就是小巧的opera,我们大多数普通人也决计搞不出来。但如果你的机器里装有vb5.0专业版,那么事情就好办多了,想试试吗?那好,let`s go! 程序的主角是一个activex控件:webbrowser。当然,缺省状态下vb的工具箱中并没有它,我们得手工加入,方法是:右击工具箱,在出现的快捷菜单中选择“部件...”,确保在弹出的对话框中选中“控件”标签,找到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;一个combobox控件: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制作浏览器
本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)