Add the following class to your code. Then call the function CaptureImage as specified below from you code:
class ScreenShot
{
public static void CaptureImage(Point SourcePoint, Point DestinationPoint, Rectangle SelectionRectangle, string FilePath)
{
using (Bitmap bitmap = new Bitmap(SelectionRectangle.Width, SelectionRectangle.Height))
{
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(SourcePoint, DestinationPoint, SelectionRectangle.Size);
}
bitmap.Save(FilePath, ImageFormat.Bmp);
}
}
}
Call function CaptureImage as below (here this referes to the form, you can replace the form object):
private void button1_Click(object sender, EventArgs e)
{
ScreenShot.CaptureImage(this.Location, new Point(this.Location.X + this.Width, this.Location.Y+this.Height), new Rectangle(this.Location.X,this.Location.Y,this.Width,this.Height), @"c:\zyx.bmp");
}