I need to move (draw) rectangle with same mouse position in regard to rectangle. There is a code where mouse is in the middle of rectangle.
private void pictureBox1_MouseMove_1(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
rect.X = e.X - (rect.Width/2);
rect.Y = e.Y - (rect.Height/2);
rect.Width = rect.Width;
rect.Height = rect.Height;
pictureBox1.Invalidate();
}
}
You need to store the mouse position in the MouseDown handler and take into account that offset rather than just centering it.
Assuming you store the coordinates (relative to rect) in MouseDown: