8

I'm trying to create an application in C#.NET that mimics the ability of the Windows 7 snipping tool, where when the application is run (or by a particular keystroke or however I choose to initiate it), the user can draw a rectangle on the screen no matter which window has focus, in order to capture a rectangular snapshot of the desktop.

I already know how to utilize the Graphics.CopyFromScreen() method in order to save a snapshot given a particular rectangle, but where I'm stumped is the actual rectangular selection and how to obtain the bounds from that.

William Thomas
  • 2,108
  • 3
  • 22
  • 32
  • It isn't altogether clear what is being asked here, whether it's about how to draw a rectangle on the desktop or getting the right coordinates, and as such the accepted answer which is equally vague, is of little use to future visitors, so I closed it. If you make it clearer exactly what you were asking for, then perhaps the answer could be made clearer as well, and the question reopened. – Lasse V. Karlsen May 10 '12 at 09:59

2 Answers2

8

The TeboScreen: Basic C# Screen Capture Application on Code Project does exactly this.

Holding down the left mouse button, the user draws a rectangle specifying which part of the screen they wish to capture. ... The mouse_Move event is used to decide on whether the user is drawing, dragging(moving) or resizing the selection area.

Joshua Drake
  • 2,704
  • 3
  • 35
  • 54
1

The user doesn't actually draw a rectangle on the screen, but on a captured image. The sequence of events that need to happen when the user invokes your tool is:

  1. Capture the entire desktop
  2. Create a borderless window the size of the screen (or one that spans ALL the screens, perhaps using this method here) and set separate images that map to screen positions/dimensions to their respective screenshots.
  3. Allow the user to make a rubberband selection on your form, using the code here.
  4. Once the user has finished selecting the region create a Bitmap as large as the users selection.
  5. Find the intersections of the users rectangle with your images
  6. Copy those regions one by one to the image you created in step 4.
  7. Save this image.
  8. Weep for joy.
Community
  • 1
  • 1
Ani
  • 10,826
  • 3
  • 27
  • 46