0% found this document useful (0 votes)
45 views2 pages

'TO DO: Add Path To YOUR Picture File Here: "E:/Down/Tiger - BMP"

This document contains code for dragging and zooming a picture within a picture box. The dragging section defines variables to store the picture, its dimensions, and mouse position. It loads a picture and scales it to fit the picture box. Mouse movement updates the picture position, and mouse up finalizes the new position. The zooming section takes a picture box and zoom amount as parameters, resizes the box and redraws the scaled picture within it. Example code shows it used on a picture box with zoom in/out buttons.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views2 pages

'TO DO: Add Path To YOUR Picture File Here: "E:/Down/Tiger - BMP"

This document contains code for dragging and zooming a picture within a picture box. The dragging section defines variables to store the picture, its dimensions, and mouse position. It loads a picture and scales it to fit the picture box. Mouse movement updates the picture position, and mouse up finalizes the new position. The zooming section takes a picture box and zoom amount as parameters, resizes the box and redraws the scaled picture within it. Example code shows it used on a picture box with zoom in/out buttons.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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