I want to move a pictureBox using my mouse so I got till here:
private void pictureB_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawImage(image, recLoc);
}
private void pictureB_MouseDown(object sender, MouseEventArgs e)
{
WorkAble = true;
choosingPoint.X = e.X;
choosingPoint.Y = e.Y;
lastPoint.X = e.X;
lastPoint.Y = e.Y;
}
private void pictureB_MouseMove(object sender, MouseEventArgs e)
{
if (WorkAble)
{
recLoc.X = e.X - choosingPoint.X;// + lastPoint.X;
recLoc.Y = e.Y - choosingPoint.Y;// + lastPoint.Y;
pictureB.Refresh();
}
}
private void pictureB_MouseUp(object sender, MouseEventArgs e)
{
WorkAble = false;
lastPoint.X = e.X;
lastPoint.Y = e.Y;
}
// recLoc = pictureBox Location.
well, it works great.. However not perfectly..
What I mean is once the KeyUp event is executed, and you click again the image will return to the 0, 0 point of the pictureBox.
To overcome that I added the lastPoint point and in the mouse move I add its values.
So in the one hand it does draw the image in the last dropped point, however the mouse will be on the 0, 0 point of to the image and not in the place I clicked – on the image. Like if I click on the center of the image the mouse will be on the 0, 0 point..
any suggestions how to fix it?
Make incremental changes to “recLoc” to avoid losing the original location: