我如何更改在坐标的图片框上绘制时不是从第一次按下鼠标和从图片框的左下角开始的代码?
private void Pic_MouseUp(object sender, MouseEventArgs e)
{
toDraw = false;
}
private void Pic_MouseMove(object sender, MouseEventArgs e)
{
if (toDraw)
{
topLeft = new Point
{
X = pointBegin.X < e.X ? pointBegin.X : e.X,
Y = pointBegin.Y < e.Y ? pointBegin.Y : e.Y
};
bottomRight = new Point
{
X = pointBegin.X > e.X ? pointBegin.X : e.X,
Y = pointBegin.Y > e.Y ? pointBegin.Y : e.Y
};
Pic.Invalidate();
}
}
private void Pic_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawRectangle(new Pen(Color.DarkOrange, 2),
new System.Drawing.Rectangle(topLeft.X, topLeft.Y,
bottomRight.X - topLeft.X, bottomRight.Y - topLeft.Y));
dotLeftX = topLeft.X;
X1.Text = "X1: " + dotLeftX.ToString();
dotLeftY = topLeft.Y;
Y1.Text = "Y1: " + dotLeftY.ToString();
dotRightX = bottomRight.X;
X2.Text = "X2: " + dotRightX.ToString();
dotRightY = bottomRight.Y;
Y2.Text = "Y2: " + dotRightY.ToString();
}