Click here to Skip to main content
13,346,487 members (65,233 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


13 bookmarked
Posted 24 Jun 2012

Screenshot Program

, 24 Jun 2012
Rate this:
Please Sign up or sign in to vote.
A Windows form application, minimized in tray and waiting for specific keyboard event to create screenshots and save them as images.


A complete application to capture screenshots while it is working in the background and save them as images. This project it was build on a KeyboardListener project, found in CodeProject

Also resizing the output image is available 


Using the code

The first basic function is the capture of the actual screen and not of the current active window.

I have cheated a little as a trigger the 'PrintScreen' button and later i retrieve the image from the clipboard. 

Image img;
private int imgNumber = 1;
private void CaptureScreen()
    img = GetImageFromClipboard();
    if (ResizeCheckBox.Checked)
        img = resizeImage(img, imageSize);
    string _fileName = Properties.Settings.Default.SavePath + "/" + Properties.Settings.Default.FileName;
    if (!File.Exists(_fileName + ".jpg"))
        _fileName += "";
    while(File.Exists(_fileName + ".jpg"))
        _fileName += " - (" + imgNumber + ")";
    img.Save(_fileName + ".jpg", ImageFormat.Jpeg);
// Get image From the Clipboard If there is any
public static Image GetImageFromClipboard()
    Image clipImage = null;
    if (Clipboard.ContainsImage())
        clipImage = Clipboard.GetImage();
    return clipImage;

To import KeyboardListener is too simple as it only needs an EventHandler.

public partial class ScreenShot : Form
    KeyboardListener.s_KeyEventHandler += new EventHandler(KeyboardListener_s_KeyEventHandler);
private void KeyboardListener_s_KeyEventHandler(object sender, EventArgs e)
    KeyboardListener.UniversalKeyEventArgs eventArgs = (KeyboardListener.UniversalKeyEventArgs)e;
    string capturedKey = string.Format("Key = {0}  Msg = {1}  Text = {2}", eventArgs.m_Key, eventArgs.m_Msg, eventArgs.KeyData);
    //An output example of the capturedKey string
    // 'Key = 32  Msg = 257  Text = Space'

    // 256 : key down    257 : key up
    if (eventArgs.m_Msg == 256)

After all, resizing the image is not a big deal.  

Create a new Bitmap with the target size and then use the System.Drawing.Graphics to redraw the image to fit the bitmap's size. 

//Resize Image to a specific Size
private static Image resizeImage(Image imgToResize, Size size)
    Bitmap newImage = new Bitmap(size.Width, size.Height);
    using (Graphics gr = Graphics.FromImage(newImage))
        gr.SmoothingMode = SmoothingMode.AntiAlias;
        gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
        gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
        gr.DrawImage(imgToResize, new Rectangle(0, 0, size.Width, size.Height));
    return (Image)newImage;


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Semertzidis Aris
Software Developer
Greece Greece

You may also be interested in...

Comments and Discussions

QuestionProgram crash on Win 7 32bit Pin
Kiran Satish2-Jul-12 11:07
memberKiran Satish2-Jul-12 11:07 
GeneralRe: Program crash on Win 7 32bit Pin
Southmountain29-Nov-15 6:37
memberSouthmountain29-Nov-15 6:37 
QuestionThank You Pin
Patrick Harris26-Jun-12 19:57
memberPatrick Harris26-Jun-12 19:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180111.1 | Last Updated 24 Jun 2012
Article Copyright 2012 by Semertzidis Aris
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid