Screen Capture Class For C#

A class that will help you take screenshots quickly and easily.

ScreenCapture

Following are the features of this class:

  • Take screenshot of the whole screen
  • Take screenshot of a particular area using a Rectangle
  • Copy the screenshot to Clipboard.
  • Save the screenshot straight after it is captured.
  • All popular image formats are supported.

How to use?

To import this class into your C# project all you have to do is to drag and drop the “ScreenCapture.cs” file into your project.

It is very simple to use this class. Here’s an overview of all the features:

// Add this code to the top of your code
// i.e: add it above "public Form1() { ......"

SC.ScreenCapture SC = new SC.ScreenCapture();

// To take a screenshot of the whole screen
// Use this code:

SC.CaptureScreen();

// If you want to save the screenshot straight after it is taken
// Use this code:
// Replace "C:\\screenshot.jpg" with your own path

SC.CaptureScreen(@"C:\screenshot.jpg");

// To take screenshot of a particular area
// Use this code:
// Replace "Rect" with a Rectangle

SC.CaptureRectangle(Rect);

// To save the screenshot straight after it is taken
// Use this code:
// Replace "C:\screenshot-rect.jpg" with your own path and "Rect" with a rectangle.

SC.CaptureRectangle(Rect, "C:\\screenshot-rect.jpg");

// Note: Use the code below after you've taken a screenshot.
// To copy the screenshot to Clipboard
// Use this code

SC.CopyToClipboard();

The above instructions showed you all the features this class offers. However, if you want to see this class in acton. Then I’ve made a simple application for you, which uses this class. Download the class alone or the sample application below:

Dowload the ScreenCapture class and a sample application

ScreenCapture Class – Download Now (1 Kb)

Sample Application – Download Now (46 Kb)

12 thoughts on “Screen Capture Class For C#

  1. It makes sense on paper, but does not import properly into C#. Getting CaptureRectangle type doesn’t exist within the context.

    Included ScreenCapture.cs and even tried using CS; in the includes section… Any Ideas?

  2. I’d like to use this program to capture a rectangle. How would I go about getting the button to capture predefined coordinates of the screen??

    IE:
    public void button2_Click(object sender, EventArgs e)
    {
    CaptureRectangle(100,100,20,20);
    }

    • Include the ScreenCapture.cs file into your project.

      Declare this class-level variable:

      SC.ScreenCapture Capture = new SC.ScreenCapture();

      To capture an image of predefined coordinates and save it in a Bitmap use this code for your button:

      public void button2_Click(object sender, EventArgs e)
      {
      Bitmap screenshot;
      screenshot = Capture.CaptureRectangle(100,100,20,20);
      }

  3. Thanks for the quick response, but it still returns errors about its arguments. Looking at the actually CaptureRectangle statement it wants Rectangle rect, string fileName. Maybe i have to declare what the rectangle is elsewhere, i’ll putz around with it some more, thanks.

    • Sorry, I forgot that.

      Declare a Rectangle class instance and use it as an argument:

      public void button2_Click(object sender, EventArgs e)
      {
      Rectangle rect = new Rectangle(100,100,20,20);
      Bitmap screenshot;
      screenshot = Capture.CaptureRectangle(rect);
      }

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>