views:

20

answers:

2

I am trying to capture a screenshot using CopyFromScreen. However method signature is a bit confusing for me.

It looks like this:

public void CopyFromScreen(
    Point upperLeftSource,
    Point upperLeftDestination,
    Size blockRegionSize
)

Why there are 3 parameters instead of 2? And why there are both upperLeftCorner. In my understanding you can describe a square area on a surface using two points (upper left corner and bottom right corner). This could describe area of any size and in any position.

So the question is: how do I use this method to capture an area denoted: (X0,Y0) (X1,Y1)?

+2  A: 

The upperLeftDestination parameter tells it where in your image to draw the copy.
You probably want that to be 0, 0.

SLaks
Suppose you just wanted to save the captured rectangle, perhaps to a file, for later viewing?
GregS
@GregS: Then you would create a `Bitmap` object, use `Graphics.FromImage`, then call `Save`.
SLaks
+2  A: 

upperLeftDestination is the point in your new image where you want to place the image you have copied.

To copy a 50x50 square from the screen starting at the top left of the screen:

graphics.CopyFromScreen(new Point(0,0), new Point(0, 0), new Size(50, 50));

To copy a 50x50 square from the screen starting at (100, 100):

graphics.CopyFromScreen(new Point(100, 100), new Point(0, 0), new Size(50, 50));

To copy a 50x50 square from the top left of the screen into, say, a 60x60 image and give it an even border of 5px on all sides you'd do:

graphics.CopyFromScreen(new Point(0, 0), new Point(5, 5), new Size(50, 50));
George