Screen Capture Application using C#

This is a detailed tutorial about making a simple screen capture application in C#. You will be learning how to take a screenshot, view it and save it.

Setting up the Form

For this tutorial we will need two buttons, a timer, SaveFileDialog and a PictureBox. Here’s how you should setup the controls:

  1. Add a button and set its “Text” property to “Take Screenshot” and “Name” property to “button1”.
  2. Add another button and set the “Text” property to “Save Screenshot”, set its “Enabled” property to “False” and “Name” property to “button2”.
  3. Add a timer and set its “Interval” to “500” and make sure it is enabled.
  4. Now add SaveFileDialog and set “Filter” to “JPEG Files|*.jpg|GIF Files|*.gif|PNG Files|*.png “.
  5. Finally, add a Picturebox.

The form is read now. Lets get on with the code.

The Code

Declare these variables at the top of the form; i.e just above “public Form1() { …… “.

Now double-click the “Take Screenshot” button to add the Click event to it and use this code:

We started the Timer in the above code. Now lets put it to some use.

Double-click the timer which will automatically add the “Tick” event for it. Use this code:

Capturing the screenshot and showing it on the picturebox part is done. Let’s work on the Save Screenshot button.

Double-click the Save Screenshot button to add the “Click” event. Use this code and we done.

Source Code

Download Now (36 Kb)

Feedback and comments are welcome.

Leave a Reply

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