在窗体构造函数(在InitializeComponent()之后,调用),添加:
monitor.MouseMove += new MouseEventHandler(monitor_MouseMove);
monitor.MouseLeave += new EventHandler(monitor_MouseLeave);
monitor.MouseClick += new MouseEventHandler(monitor_MouseClick);
现在,添加以下到您的Form类:
const int adjustX = -50;
const int adjustY = -50;
public Size boxSize = new Size(100, 100);
public int lastX = 2 * adjustX;
public int lastY = 2 * adjustY;
private void monitor_MouseMove(object sender, MouseEventArgs e) {
if (e.X != lastX || e.Y != lastY) {
Graphics g = monitor.CreateGraphics();
g.CopyFromScreen(monitor.PointToScreen(new Point(lastX + adjustX, lastY + adjustY)), new Point(lastX + adjustX, lastY + adjustY), boxSize, CopyPixelOperation.DestinationInvert);
lastX = e.X;
lastY = e.Y;
g.CopyFromScreen(monitor.PointToScreen(new Point(e.X + adjustX, e.Y + adjustY)), new Point(e.X + adjustX, e.Y + adjustY), boxSize, CopyPixelOperation.DestinationInvert);
}
}
void monitor_MouseLeave(object sender, EventArgs e) {
Graphics g = monitor.CreateGraphics();
g.CopyFromScreen(monitor.PointToScreen(new Point(lastX + adjustX, lastY + adjustY)), new Point(lastX + adjustX, lastY + adjustY), boxSize, CopyPixelOperation.DestinationInvert);
lastX = 2 * adjustX;
lastY = 2 * adjustY;
}
最后,在你的鼠标点击处理程序:
void monitor_MouseClick(object sender, MouseEventArgs e) {
}
你将不得不添加任何你想做的选择区域。您可以将它复制到另一个图片框,将其保存为位图,无论如何。