You are on page 1of 2

Dragging picture

1. Option Explicit
2.
3. Private mPic As Picture
4. Private mPicWidth As Single
5. Private mPicHeight As Single
6. Private mCurrentX As Single
7. Private mCurrentY As Single
8. Private mLeft As Single
9. Private mTop As Single
10.
11. Private Sub Form_Load()
12. Set mPic = LoadPicture("E:\Down\Tiger.bmp") 'TO DO: Add path
to YOUR Picture file here
13.
14. mPicWidth = Me.ScaleX(mPic.Width, vbHimetric,
Picture1.ScaleMode)
15. mPicHeight = Me.ScaleY(mPic.Height, vbHimetric,
Picture1.ScaleMode)
16. Picture1.AutoRedraw = True
17. ShowPictureAtPosition mLeft, mTop
18. End Sub
19.
20. Private Sub Picture1_MouseMove(Button As Integer, Shift As
Integer, X As Single, Y As Single)
21. If Button = 0 Then
22. mCurrentX = X
23. mCurrentY = Y
24. ElseIf Button = vbLeftButton Then
25. ShowPictureAtPosition X + mLeft - mCurrentX, Y + mTop -
mCurrentY
26. End If
27. End Sub
28.
29. Private Sub ShowPictureAtPosition(pX As Single, pY As Single)
30. With Picture1
31. .Cls
32. .PaintPicture mPic, pX, pY, mPicWidth, mPicHeight
33. End With
34. End Sub
35.
36. Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer,
X As Single, Y As Single)
37. mLeft = X + mLeft - mCurrentX: mTop = Y + mTop - mCurrentY
38. End Sub





Zooming
1. Public Sub ZoomPicture(pct As PictureBox, zoom As Double)
2. With pct
3. .Width = .Width * zoom
4. .Height = .Height * zoom
5. .PaintPicture .Picture, 0, 0, .ScaleWidth, .ScaleHeight
6. End With
7. End Sub
8.
9. 'usage (I had two buttons in control array)
10. Private Sub Command1_Click(index As Integer)
11. '============================================
12.
13. If index = 0 Then
14. ZoomPicture Picture1, 1.1
15. Else
16. ZoomPicture Picture1, 0.9
17. End If
18.
19. End Sub

You might also like