【VB开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了VB开源代码-ScrollBar.frm的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
VERSION 5.00
Begin VB.Form ScrollBar
Caption = "Form1"
ClientHeight = 4980
ClientLeft = 60
ClientTop = 345
ClientWidth = 7215
LinkTopic = "Form1"
ScaleHeight = 4980
ScaleWidth = 7215
StartUpPosition = 3 '窗口缺省
Begin VB.PictureBox Picture1
Height = 4575
Left = 0
ScaleHeight = 4515
ScaleWidth = 6915
TabIndex = 0
Top = 0
Width = 6975
Begin VB.VScrollBar VScroll1
Height = 4185
Left = 6600
TabIndex = 2
Top = 0
Width = 300
End
Begin VB.HScrollBar HScroll1
Height = 300
Left = 0
TabIndex = 1
Top = 4200
Width = 6610
End
Begin
VB.PictureBox Picture2
Appearance = 0 'Flat
BackColor = &H80000005&
BorderStyle = 0 'None
ForeColor = &H80000008&
Height = 4215
Left = 0
ScaleHeight = 4215
ScaleWidth = 6615
TabIndex = 3
Top = 0
Width = 6615
End
End
End
Attribute VB_Name = "ScrollBar"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub Form_Load()
'将 Autosize 设置为 True,以使 Picture2 的边界
'扩展到实际的位图大小。
Picture2.AutoSize = True
'将每个图片框的 BorderStyle 属性设置为 None。
Picture1.BorderStyle = 0
Picture2.BorderStyle = 0
'加载位图。
Picture2.Picture = _
LoadPicture("旷野中的小屋.jpg")
'初始化两个图片框的位置。
Picture1.Move 0, 0, ScaleWidth - VScroll1.Width, _
ScaleHeight - HScroll1.Height
Picture2.Move 0, 0
'将水平滚动条定位。
HScroll1.Top = Picture1.Height - 300
HScroll1.Left = 0
HScroll1.Width = Picture1.Width - 300
'将垂直滚动条定位。
VScroll1.Top = 0
VScroll1.Left = Picture1.Width - 300
VScroll1.Height = Picture1.Height - 300
'设置滚动条的 Max 属性。
HScroll1.Max = Picture2.Width - Picture1.Width
VScroll1.Max = Picture2.Height - Picture1.Height
VScroll1.LargeChange = 50
VScroll1.SmallChange = 5
HScroll1.LargeChange = 50
HScroll1.SmallChange = 5
'判断子图片框是否将充满屏幕。
'若如此,则无需使用滚动条。
VScroll1.Visible = (Picture1.Height < _
Picture2.Height)
HScroll1.Visible = (Picture1.Width < _
Picture2.Width)
End Sub
Private Sub HScroll1_Change()
Picture2.Left = -HScroll1.Value
End Sub
Private Sub VScroll1_Change()
Picture2.Top = -VScroll1.Value
End Sub
Private Sub Form_Resize()
'调整窗体大小时,改变 Picture1
'的尺寸。
Picture1.Height = Me.Height
Picture1.Width = Me.Width
'重新初始化图片和滚动条的
'位置。
Picture1.Move 0, 0, ScaleWidth - VScroll1.Width, _
ScaleHeight - HScroll1.Height
Picture2.Move 0, 0
HScroll1.Top = Picture1.Height - 300
HScroll1.Left = 0
HScroll1.Width = Picture1.Width - 300
VScroll1.Top = 0
VScroll1.Left = Picture1.Width - 300
VScroll1.Height = Picture1.Height - 300
HScroll1.Max = Picture2.Width - Picture1.Width
VScroll1.Max = Picture2.Height - Picture1.Width
'检查是否需要滚动条。
VScroll1.Visible = (Picture1.Height < _
Picture2.Height)
HScroll1.Visible = (Picture1.Width < _
Picture2.Width)
End Sub