我在我的程序中有一个绘图选择,看看我从我的图片中切割了多少像油漆一样,我的问题是,当我离开鼠标时,如何从图片中删除区域的选择?
这是我的代码:
private void ChoosedImage_Paint(object sender, PaintEventArgs e)
{
var pen = new Pen(this.selectionBrush);
pen.Color = Color.Black;
if (choosedImage.Image != null)
{
if (Rect != null && Rect.Width > 0 && Rect.Height > 0)
{
e.Graphics.DrawRectangle(pen, Rect);
}
}
}
private void ChoosedImage_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
return;
var tempEndPoint = e.Location;
Rect.Location = new Point(
Math.Min(this.seleciontStartPoint.X, tempEndPoint.X),
Math.Min(this.seleciontStartPoint.Y, tempEndPoint.Y));
Rect.Size = new Size(
Math.Abs(this.seleciontStartPoint.X - tempEndPoint.X),
Math.Abs(this.seleciontStartPoint.Y - tempEndPoint.Y));
choosedImage.Invalidate();
}
我试图通过mouseUp使图形无效,但它不起作用。所以我不知道我怎么能用mouseUp来处理它