Name: Anonymous 2012-05-18 11:30
I am looking to Move a pictureBox inside a panel without it leaving the Bounds of it. So far I have this code which only prevents it from leaving the pictureBox1.Top & pictureBox1.Left.
Here is the code, please help me finish it:
int x;
int y;
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
panel1.Left += (e.X - x);
panel1.Top += (e.Y - y);
}
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
x = e.X;
y = e.Y;
}
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (pictureBox1.Left + (e.X - x) > 0)
pictureBox1.Left += (e.X - x);
if (pictureBox1.Top + (e.Y - y) > 0)
pictureBox1.Top += (e.Y - y);
}
}
Here is the code, please help me finish it:
int x;
int y;
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
panel1.Left += (e.X - x);
panel1.Top += (e.Y - y);
}
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
x = e.X;
y = e.Y;
}
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (pictureBox1.Left + (e.X - x) > 0)
pictureBox1.Left += (e.X - x);
if (pictureBox1.Top + (e.Y - y) > 0)
pictureBox1.Top += (e.Y - y);
}
}