PictureBox Scrolling

B

bwilde

Hello,

Here's what I'd like to have in a form that I'm creating: A picture
box that contains an image that is significantly larger than the box.
I'd like for there to be scroll bars, but also to enable the user to
click and drag the image directly, with the scroll bars updating to
reflect which section of the image is shown on the screen.

I've created a panel and set it to AutoScroll, and put a PictureBox
into it. When the scroll bars are used, things work perfectly. When
I try to click and drag on the image (and update the Location of the
picture), the image moves as it should, but the scroll bars do not.
What happens is that the handles always stay in the same place, but
get wider or narrower as I change the .Location of the picture box.
Also, if I move the image to the upper left corner, the scroll bars
disappear completely, and if I move it to the bottom right, the scroll
bars have tiny scroll handles.

Any ideas of how to get this right?

Thanks,
Ben
 
P

Peter Duniho

[...]
I've created a panel and set it to AutoScroll, and put a PictureBox
into it. When the scroll bars are used, things work perfectly. When
I try to click and drag on the image (and update the Location of the
picture), the image moves as it should, but the scroll bars do not.
[...]

Any ideas of how to get this right?

Instead of changing the Location property of the PictureBox when the
user drags, you should be changing the AutoScrollPosition property of
the Panel.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top