Capturing your computer screen is a nice trick to know that may help in all sorts of situations, ranging from creating tutorials to capturing web moments for posterity. There is a screen capture program that helps you capture your desktop screen. This program will capture the user's screen when the PrtScn button is press. The picture will be displayed on an image control on the form.
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace PrtScreen
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{ //check if the is an image in the clipboard
if (Clipboard.ContainsImage())
{
//display the clipboard image in the picurebox
imgPrintScreen.SizeMode = PictureBoxSizeMode.StretchImage;
imgPrintScreen.Image = Clipboard.GetImage();
}
}
SaveFileDialog sfd = new SaveFileDialog();
private void btnSave_Click(object sender, EventArgs e)
{
sfd.Filter = "Jpg|*.jpg|Bmp|*.bmp";
//check if the picturebox contains image
if (imgPrintScreen.Image != null)
{
if (sfd.ShowDialog() == DialogResult.OK)
{
if (sfd.FilterIndex == 1)
{
imgPrintScreen.Image.Save(sfd.FileName +/*If you dont include this extension u wont be able to set the image as a wallpaper,
* unless u edit it using image editor*/
".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
}
else if (sfd.FilterIndex == 2)
{
imgPrintScreen.Image.Save(sfd.FileName + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);
}
}
}
else
{
MessageBox.Show("The is no Picture to save", "Info");
}
}
}
}