1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| Option Explicit
Public WithEvents VBar As VScrollBar
Public WithEvents HBar As HScrollBar
Public WithEvents InnerPicture As PictureBox
Public WithEvents FramePicture As PictureBox
Const DFC_SCROLL = 3 ' Scroll bar
Private Type RECT
Left As Long
top As Long
Right As Long
Bottom As Long
End Type
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function DrawFrameControl Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal un1 As Long, ByVal un2 As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Sub SetScrollBar()
' See if we need the vertical scroll bar.
If InnerPicture.Height <= FramePicture.ScaleHeight Then
VBar.Enabled = False
Else
' Set scroll bar properties.
InnerPicture.top = 0
VBar.Min = 0
VBar.Max = FramePicture.ScaleHeight - InnerPicture.Height
VBar.LargeChange = FramePicture.ScaleHeight
VBar.SmallChange = FramePicture.ScaleHeight / 5
VBar.Enabled = True
End If
' See if we need the vertical scroll bar.
If InnerPicture.Width <= FramePicture.ScaleWidth Then
HBar.Enabled = False
Else
' Set scroll bar properties.
InnerPicture.Left = 0
HBar.Min = 0
HBar.Max = FramePicture.ScaleWidth - InnerPicture.Width
HBar.LargeChange = FramePicture.ScaleWidth
HBar.SmallChange = FramePicture.ScaleWidth / 5
HBar.Enabled = True
End If
End Sub
Private Sub VBar_Change()
InnerPicture.top = VBar.Value
End Sub
Private Sub VBar_Scroll()
InnerPicture.top = VBar.Value
End Sub
Private Sub HBar_Change()
InnerPicture.Left = HBar.Value
End Sub
Private Sub HBar_Scroll()
InnerPicture.Left = HBar.Value
End Sub
Sub ReSizeArea()
VBar.TabStop = False: HBar.TabStop = False
InnerPicture.Left = ((FramePicture.Width) - InnerPicture.Width) / 2
InnerPicture.top = (FramePicture.Height - InnerPicture.Height) / 2
SetScrollBar
End Sub |
Partager