我需要移動(繪製)與矩形相同的鼠標位置的矩形。有一個代碼,鼠標位於矩形的中間。將矩形移動到與矩形相同的鼠標位置?
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();
}
}
問題應該有一個問號 – Snowbear