views:

84

answers:

1

I'm looking for a tool/control/component that i can use to position over image control of my win form, and it will pick a screen shot from specific region the user will select.

The user won't be able to move this "camera" out of the form, and after picking the partial image from the image control, i need the camera will mark the copied area by color it with special layer or cut it out, no matter how.

Ill be thankful for any idea and to get your opinion about the suggested component.

We are working with .NET fx 3.5 with Winforms application.

Thanx!

+1  A: 

In your Form constructor (after the InitializeComponent(); call), add:

monitor.MouseMove += new MouseEventHandler(monitor_MouseMove);
monitor.MouseLeave += new EventHandler(monitor_MouseLeave);
monitor.MouseClick += new MouseEventHandler(monitor_MouseClick);

Now add the following to your Form class:

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;
}

Finally, in your mouse click handler:

void monitor_MouseClick(object sender, MouseEventArgs e) {

}

You will have to add whatever you want done with the selected area. You could copy it to another picture box, save it as a bitmap, whatever.

Chris Judge