Home » Category » Microsoft Visual Basic

Microsoft Visual Basic: Zoom & Move Image Inside Picturebox

104| Mon, 03 Dec 2007 22:40:00 GMT| promocom| Comments (5)
I have a database of hi-res images (Antiques) of different sizes. Currently on the form I have various textboxes and a small imagebox displaying the image.

I would like to have a 2nd larger box of a set dimension (600x600) to put the image in and be able to zoom in and center any part, kinda like mapquest, or move the image within the frame, maybe by clicking or dragging on the image itself.

Keywords & Tags: zoom, move, image, inside, picturebox, microsoft, visual basic, vb

URL: http://www.programmerbase.com/visual-basic/560705/
 
«« Prev - Next »» 5 helpful answers below.
You could try using Image control inside Picturebox so you can drag it arround.

rhinobull | Mon, 03 Dec 2007 18:26:00 GMT |

interesting... I'll play around with that, thanks

promocom | Mon, 03 Dec 2007 18:27:00 GMT |

I found this code from "BuggyProgrammer" that does almost what I want, but for aesthetic purposes would like some kind of routine to constrain the edges of the inside image to the picturebox frame as it is moved. So none of the background of the picturebox shows.

-----------------------

Try this. Put a picturebox (picture1) on the form. Put another picturebox (picture2) on the form and set the picture to something. This code then goes into the form:Dim curX As Long
Dim curY As Long
Dim prevX As Long
Dim prevY As Long

Private Sub Form_Load()
curX = 0
curY = 0
Picture1.BackColor = Picture1.BackColor 'clear canvas (faster than .Cls)

Picture1.PaintPicture Picture2.Picture, curX, curY 'draw the picture onto the new coords
Picture1.Refresh 'refresh

End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
curX = curX + (X - prevX) / 2 'moves 1px in x-axis per 2px
curY = curY + (Y - prevY) * 2 'moves 2px in y-axis per 1px

Picture1.BackColor = Picture1.BackColor 'clear canvas (faster than .Cls)

Picture1.PaintPicture Picture2.Picture, curX, curY 'draw the picture onto the new coords
Picture1.Refresh 'refresh

End If

prevX = X
prevY = Y
End Subdrag the picture in picture1 and it will move the image.

Edit: Added tags for clarity. - Hack

promocom | Mon, 03 Dec 2007 18:28:00 GMT |

Here's an awesome program that I wrote that does it in real time :thumb:

http://www.vbforums.com/attachment.php?attachmentid=34735

jacobroman | Mon, 03 Dec 2007 18:29:00 GMT |

HeHe! That's way cool Jacob... but somewhat of an overkill for what I want to do. :)
Thanks!

promocom | Mon, 03 Dec 2007 18:30:00 GMT |

Microsoft Visual Basic Hot Answers

Microsoft Visual Basic New questions

Microsoft Visual Basic Related Categories