C# - Screenshot

By , 12/25/2012
(0 ratings)
If you want to create a screenshot out of your application, this is the perfect snippet suitable to your needs.

Author: Volker Steitz, translation by Michael List
using System;
using System.Drawing;
using System.Windows.Forms;

/// <summary>
/// Saves an image of the screen to the specified path.
/// </summary>
/// <param name="Location">Path, where output file will be saved at.</param>
/// <returns>Path of the successfully saved image or errormessage</returns>

public string ScreenToPicture(string Location)
        Size currentScreenSize = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
        Bitmap ScreenToBitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
        System.Drawing.Graphics gGraphics = System.Drawing.Graphics.FromImage(ScreenToBitmap);

        gGraphics.CopyFromScreen(new Point(0, 0), new Point(0, 0), currentScreenSize);

        return Location;

    catch (Exception ex)
        return ex.Message;
Tagged with screenshot.



Log in, to comment!