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 |