Click here to Skip to main content
15,920,618 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
using System.Drawing;
using System.Drawing.Imaging; 


^ Imports
private void button8_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:\printscreen.jpg", ImageFormat.Jpeg);
   }



^ Code to take screenshot.

Is it possible to take a screenshot of the window rather than the whole screen?


-Thanks.
Posted

Assuming it is fully visible, then just use the form properties:
Bitmap printscreen = new Bitmap(Width,Height);
Graphics graphics = Graphics.FromImage(printscreen as Image);
graphics.CopyFromScreen(Left, Top, 0, 0, Size);
printscreen.Save(@"F:\Temp\screen.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
Will capture just the area you want of the form your button is in.
 
Share this answer
 
Comments
LighthouseCall 25-Mar-11 11:11am    
If I save to C: (and not K: [for example] which is a usb drive, i get this error)
A generic error occurred in GDI+.
OriginalGriff 25-Mar-11 11:21am    
That's probably permissions: save it somewhere you have red/write access to! :laugh:
Sergey Alexandrovich Kryukov 25-Mar-11 13:24pm    
Proposed as the answer.
My 5.
--SA
Screen Capture Class[^]

Just convert it to C#
 
Share this answer
 
Hope this[^] might help you.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900