Winforms(.NET)的截图选取器组件

时间:2009-08-20 08:23:04

标签: .net winforms components

我正在寻找一个工具/控制/组件,我可以使用它来定位我的胜利形式的图像控制,它将从用户将选择的特定区域中选择一个屏幕截图。

用户将无法将此“相机”移出表格,并且在从图像控件中拾取部分图像后,我需要相机将通过特殊图层将其复制区域标记或剪切不管怎么样。

感谢任何想法,并对建议的组件发表意见。

我们正在使用带有Winforms应用程序的.NET fx 3.5。

感谢名单!

1 个答案:

答案 0 :(得分:1)

在Form构造函数中(在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) {

}

您必须在所选区域添加您想要的任何内容。您可以将其复制到另一个图片框,将其另存为位图,无论如何。