all groups > c# > april 2007 >
You're in the

c#

group:

How to drag a picturebox inside a panel control?


How to drag a picturebox inside a panel control? Steven Garrad
4/30/2007 10:47:40 PM
c#: 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,
Re: How to drag a picturebox inside a panel control? Alex Meleta
4/30/2007 11:43:29 PM
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




[quoted text, click to view]

AddThis Social Bookmark Button