C#中关于鼠标获取感兴趣区域方式,分享下
在Form1.cs中添加
private void imageBox1_MouseDown(object sender, MouseEventArgs e)
{
_x = e.X;
_y = e.Y;
isDragging = true;
}
private void imageBox1_MouseMove(object sender, MouseEventArgs e)
{
if (isDragging)
{
int sx = _x < e.X ? _x : e.X;
int sy = _y < e.Y ? _y : e.Y;
int w = Math.Abs(_x - e.X);
int h = Math.Abs(_y - e.Y);
ControlPaint.DrawReversibleFrame(lastRect, this.BackColor, FrameStyle.Dashed);
lastRect = new Rectangle(_x,_y, w,h);
ControlPaint.DrawReversibleFrame(lastRect, this.BackColor, FrameStyle.Dashed);
}
}
private void imageBo