Place a picturebox in a panel such that the picture box and the panel are in the same size. Load an image in the picturebox. In the picturebox mousedown event store the x and y positions of the mouse pointer.
Quote:
private Rectangle rect;
private bool move = false;
private void pictureBox_MouseDown(object sender, MouseEventArgs e)
{
move = true;
rect.X = e.X;
rect.Y = e.Y;
}
|
Then, in mouse move event, subtract the previous x,y position with the current x,y position of the mouse pointer and assign the subtracted value to the picturebox left and top position. This is done only when the move value is true.
Quote:
private void pictureBox_MouseMove(object sender, MouseEventArgs e)
{
if (move)
{
pictureBox.Left += e.X - rect.X;
pictureBox.Top += e.Y - rect.Y;
}
}
|
In mouse up event, change the move value to false to avoid moving the picturebox even after the mouse up event otherwise the picturebox will move when ur mouse pointer moves.
Quote:
private void pictureBox_MouseUp(object sender, MouseEventArgs e)
{
move = false;
}
|
Try this!!!