0
Reply

Pannable PictureBox [solved]

Roy S

Roy S

Jun 7 2012 11:56 AM
2.2k
My goal is to create a picturebox that can hold an image and show it at full size. If the image is too big scrollbars should appear and it should be possible to pan the image around (dragging with the left mousebutton).

I Made a new usercontrol, added a picturebox to it and set the autoscroll of the usercontrol to true. The picturebox' sizing method is set to autosize.

This got the scrollbar thing done, now only the pan bit.

I added event handlers for the mouseDown, mouseMove and mouseUp events of the picturebox. In the mouseDown I saved the position of the mouse, the position of both scrollbars and set a boolean to true so I know I'm panning. In the mousemove, I calculate the offset by subtracting the new mouselocation from the original one and added that to the original positions of the scrollbars (and put the result of that as value in the scrollbars).

This works but there's a big problem... The image begins to shake and becomes disturbed when moved around. How do I solve this (or does this happen only to me?) or is there better way to do this?

I've added the source (don't mind the including image, had to lower the quality of it by 100% to get it small enough to be uploaded).



Solved it... It was doing weird thigns because the picturebox was being moved and caused some weird locations to be obtained from e.X and e.Y.

I've solved it by using the screenlocation of the cursor (Cursor.Position) instead of e.Location.


Attachment: panzoompicturebox.rar