How can I cause a panel to scroll programatically to expose its AutoSized picture box?

"YOU AND THE ART OF ONLINE DATING" is the only product on the market that will take you step-by-step through the process of online dating, provide you with the resources to help ensure success. Get it now!

I believe your instinct is correct but your mistake is to attempt to adjust the scrollbars rather than moving the PictureBox within the scrollable panel.

I believe your instinct is correct but your mistake is to attempt to adjust the scrollbars rather than moving the PictureBox within the scrollable panel. You should intercept the MouseMove and adjust the PictureBox's Location property by the mouse movement delta — the scrollbars should automatically update to reflect the image's new location within it. Updating your code would look something like tho following (untested): private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { if (dragging) { if (e.

Button == MouseButtons. Left) { int horizontalChange = (e. X - startingX) * -1; // move the image inverse to direction dragged int verticalChange = (e.

Y - startingY); pictureBox1. Left += horizontalChange; pictureBox1. Top += verticalChange; } } startingX = e.

X; startingY = e. Y; } (Also, I would be inclined to record the starting mouse and PictureBox locations at the start of the drag and update them relative to this starting position on each MouseMove event rather than make incremental changes as the code above (and your original code does). The reason for this is that if there are any unexpected values, for whatever reason, then this will only cause a transitory effect — the next good event will self-correct.).

Thanks. I'm working with this approach. The panel control doesn't show scroll bars if you move the picture box off the top or left sides though :-( – Stuart Helwig Nov 27 '09 at 2:07 Oh, that's odd — it really should if you have AutoScroll turned on.

– Paul Ruane Nov 27 '09 at 10:28.

It is jumping because the act of scrolling the panel will throw off the mouse position by the scroll amount. You can get the "real" mouse position (relative from the upper left corner of the panel) like this: Point realPos = new Point(e. X + panel1.

AutoScrollPosition. X, e. Y + panel1.

AutoScrollPosition. Y); assuming the picture box' Location property is (0, 0). The best way to scroll the panel is to set its AutoScrollPosition property.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions