How to capture/store screen shot using C#.net

Post date: Mar 17, 2011 12:26:29 PM

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Reflection;

using System.IO;

using System.Drawing;

using System.Windows.Forms;

    public static Image GetScreenShot(bool currentScreen)

        {

            if (currentScreen)

                // Simulate Alt+PrtScn keypress.

                SendKeys.Send("{%}({PRTSC})");

            else

                // Simulate PrtScn keypress.

                SendKeys.Send("{PRTSC}");

            // Get the image from the clipboard.

            return  Clipboard.GetImage();

         }

For testing this function,

1.       Open new windows application, add form into that application

2.       Add picture(myPicture) from Toolbox into that form

3.       Add one button (btnImage)

4.       Double click the button then call this function    

myPicture.Image = GetScreenShot(true)

5.       Job is done, now you run the application by pressing F5, then click the button,  you will get image screen shot in the picture box.