469,929 Members | 1,459 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,929 developers. It's quick & easy.

How to drag a picturebox inside a panel control?

Hi All,
I have a pictureBox control inside of a panel control. The pictureBox is
larger than the panel control and I have the panel control set true for
AutoScroll so the panel displays scrolling bars.

I would like the user to be able to click and drag the image and for it to
move around within the panel control.

How would I do this?

Cheers,
Steve
Apr 30 '07 #1
1 18268
Steve,

The simple way to just move the picture by clicking is:

// Define a location before move
int x;
int y;

// Storing begin point (by the left click)
void pictureBox_MouseDown(object sender, MouseEventArgs e) {
if (e.Button == MouseButtons.Left) {
x = e.X;
y = e.Y;
} }

// Moving the picture
void pictureBox_MouseMove(object sender, MouseEventArgs e) {
if (e.Button == MouseButtons.Left) {
pictureBox1.Left += (e.X - x);
pictureBox1.Top += (e.Y - y);
} }

Alex
http://devkids.blogspot.com

Hi All,
I have a pictureBox control inside of a panel control. The pictureBox
is
larger than the panel control and I have the panel control set true
for
AutoScroll so the panel displays scrolling bars.
I would like the user to be able to click and drag the image and for
it to move around within the panel control.

How would I do this?

Cheers,
Steve

Apr 30 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Curtis Justus | last post: by
2 posts views Thread by MFRASER | last post: by
reply views Thread by Paul L | last post: by
5 posts views Thread by Christopher Kurtis Koeber | last post: by
4 posts views Thread by Thiru .Net | last post: by
6 posts views Thread by Blkpower | last post: by
reply views Thread by Truevision .Net | last post: by
reply views Thread by Jerry West | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.