browser.frm
来自「vb精彩编程希望大家有用」· FRM 代码 · 共 166 行
FRM
166 行
VERSION 5.00
Object = "{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}#1.1#0"; "shdocvw.dll"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form Form1
Caption = "小巧浏览器"
ClientHeight = 6795
ClientLeft = 60
ClientTop = 345
ClientWidth = 8475
LinkTopic = "Form1"
ScaleHeight = 6795
ScaleWidth = 8475
StartUpPosition = 3 '窗口缺省
Begin MSComctlLib.ProgressBar ProgressBar1
Height = 255
Left = 5400
TabIndex = 4
Top = 6480
Width = 2415
_ExtentX = 4260
_ExtentY = 450
_Version = 393216
Appearance = 1
End
Begin MSComctlLib.StatusBar StatusBar1
Align = 2 'Align Bottom
Height = 375
Left = 0
TabIndex = 3
Top = 6420
Width = 8475
_ExtentX = 14949
_ExtentY = 661
_Version = 393216
BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628}
NumPanels = 1
BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628}
EndProperty
EndProperty
End
Begin VB.ComboBox Combo1
Height = 300
Left = 120
TabIndex = 2
Text = "Combo1"
Top = 0
Width = 8175
End
Begin MSComDlg.CommonDialog CommonDialog1
Left = 1320
Top = 360
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.CommandButton Command1
Caption = "打开文件"
Height = 375
Left = 120
TabIndex = 1
Top = 360
Width = 855
End
Begin SHDocVwCtl.WebBrowser WebBrowser1
Height = 5535
Left = 0
TabIndex = 0
Top = 840
Width = 8415
ExtentX = 14843
ExtentY = 9763
ViewMode = 0
Offline = 0
Silent = 0
RegisterAsBrowser= 0
RegisterAsDropTarget= 1
AutoArrange = 0 'False
NoClientEdge = 0 'False
AlignLeft = 0 'False
ViewID = "{0057D0E0-3573-11CF-AE69-08002B2E1262}"
Location = ""
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Form_Load()
Combo1.Text = ""
Combo1.Top = 0 ' 设置URL地址栏起始位置
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 err1
Combo1.Width = Form1.Width - 100 ' URL地址栏宽度随窗口大小调整而变化
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
err1:
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 '如果输入网址不是以"http://"开头则自动添加
Combo1.Text = "http://" + Combo1.Text
End If
WebBrowser1.Navigate Combo1.Text ' URL地址栏保存的网站地址
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()
StatusBar1.SimpleText = "载入中…" '下载开始时状态栏显示"载入中…"
End Sub
Private Sub WebBrowser1_DownloadComplete()
StatusBar1.SimpleText = "下载完成" '下载完成时状态栏显示"下载完成"
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
Private Sub Command1_Click()
On Error GoTo err2
CommonDialog1.CancelError = True
CommonDialog1.ShowOpen '激活打开文件对话框选择文件
WebBrowser1.Navigate CommonDialog1.FileName
err2:
End Sub
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?