因此,软件研制者都想开发自己的浏览器,而Visual Basic 5.0就提供了这种功能。笔者曾经用Visual Basic 5.0开发出简单的浏览器,编译出可执行文件后很小(只有33K),并成功地把它集成到其它软件中。下面给出制作步骤和程序清单,稍加修改就可做出自己喜欢的浏览器。
1.打开一应用,打开一个Form(brower);
2.在Brower里加入Toolbar控件toolbar1,增加常用的命令按钮(如back、next、stop、refresh、home、Search、open、exit等),同时加入Imagelist控件imagelist1,并加入自己喜欢的图形,然后和toolbar1中的命令按钮对应起来。
3.加入定时器Timer控件timer1,并设置好;
4.加入Label控件label1,Caption设为“Web地址”,加入Combobox控件combo1,加入Statusbar控件statusbar1.加入Webbrowser控件browser1;
5.然后写入以下程序代码:
PublicStartingAddressAsString
DimflagAsBoolean
PrivateSubForm—Load()
OnErrorResumeNext
Me.Show
ToolBar1.Refresh
Open″d:\vb5\brow.ini″ForInputAs#2
′打开上次的WEBIP地址
Input#2,StartingAddress
Close#2
IfLen(StartingAddress)>0Then
combo1.Text=StartingAddress
combo1.AddItemStartingAddress
webbrowser1.NavigateStartingAddress
EndIf
EndSub
PrivateSubwebbrowser1—DownloadComplete()
OnErrorResumeNext
Me.Caption=webbrowser1.LocationName
EndSub
PrivateSubwebbrowser1—NavigateComplete(ByValURLAsString)
DimiAsInteger
DimbFoundAsBoolean
Me.Caption=webbrowser1.LocationName
Fori=0Tocombo1.ListCount-1
Ifcombo1.List(i)=webbrowser1.LocationURL
Then
bFound=True
ExitFor
EndIf
Nexti
flag=True
IfbFoundThen
combo1.RemoveItemi
EndIf
combo1.AddItemwebbrowser1.LocationURL,0
combo1.ListIndex=0
MousePointer=0
webbrowser1.Navigatecombo1.Text
StatusBar1.Panels(1).Text=″当前页面″+combo1.Text
flag=False
EndSub
PrivateSubcombo1—Click()
IfflagThenExitSub
Timer1.Enabled=True
MousePointer=11
StatusBar1.Panels(1).Text=″正在连接″+combo1.Text+″......″
webbrowser1.Navigatecombo1.Text
EndSub
PrivateSubcombo1—KeyPress(KeyAsciiAsInteger)
OnErrorResumeNext
IfKeyAscii=vbKeyReturnThen
combo1—Click
End If
End Sub
PrivateSubTimer1-Timer()
Ifwebbrowser1.Busy=FalseThen
Timer1.Enabled=False
Me.Caption=webbrowser1.LocationName
Else
Me.Caption=″Working...″
EndIf
EndSub
PrivateSubToolBar1-ButtonClick(ByValButtonAsButton)
OnErrorResumeNext
Timer1.Enabled=True
SelectCaseButton.Key
Case″exit″
UnloadMe
Case″Back″
webbrowser1.GoBack
Case″Forward″
webbrowser1.GoForward
Case″Refresh″
webbrowser1.Refresh
Case″Home″
webbrowser1.GoHome
Case″Search″
webbrowser1.GoSearch
Case″open″
CommonDialog1.ShowOpen
combo1.Text=CommonDialog1.filename
Case″Stop″
Timer1.Enabled=False
MousePointer=0
webbrowser1.Stop
Me.Caption=webbrowser1.LocationName
EndSelect
EndSub
该程序经编译后即是一简单普通浏览器,可方便地集成到其他软件中去。
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/