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.
4 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.
is any one know how to print the image istead of saving, i want to print
thanks in advance
in .Net 4.0, You have to include Windows.Forms namespace to work.^^
Post a Comment