Lately, I was building a simple add-on that will capture the user screen and automatically send it to the system administrator. This add-on will be plug-in into our existing systems. It will be automatically triggered if an error is detected so the system administrator can analyze the problem on-hand before going to the user to fix the error. On this blog entry, I will share the code that I used to print or capture the screen.
First you must include the following namespaces.
using System.Drawing;
using System.Drawing.Imaging;
Now here's the code that performs the print screen or capture screenshot operation.
private void button1_Click(object sender, EventArgs e)
{
Bitmap printscreen = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics graphics = Graphics.FromImage(printscreen as Image);
graphics.CopyFromScreen(0, 0, 0, 0, printscreen.Size);
printscreen.Save(@"C:\fryan0911\printscreen.jpg", ImageFormat.Jpeg);
}
For more C# coding tips & tricks, subscribe now.
Wednesday, July 01, 2009




2 comments:
Has anybody tried this? Maybe someone has the full code, the one that sends the mail and all.
Yes, this does work and saves it. If you want to display or e-mail it's going to be a little more work. If you have a picture box on your form, you can view the picture with
image1.Load(@"C:\printscreen.jpg");
image1.Show();
Where image1 is my picture box and the parameter for Load is the string URL of your picture.
Post a Comment