Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the screenshot of the form

Tags:

c#

.net

winforms

Any method to output the screenshot of an active form?

like image 338
user496949 Avatar asked Feb 26 '11 01:02

user496949


People also ask

How do you capture a screenshot on a PC?

Windows. Hit the PrtScn button/ or Print Scrn button, to take a screenshot of the entire screen: When using Windows, pressing the Print Screen button (located in the top right of the keyboard) will take a screenshot of your entire screen. Hitting this button essentially copies an image of the screen to the clipboard.


1 Answers

Use the Control.DrawToBitmap() method. For example:

    private void timer1_Tick(object sender, EventArgs e) {         var frm = Form.ActiveForm;         using (var bmp = new Bitmap(frm.Width, frm.Height)) {             frm.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));             bmp.Save(@"c:\temp\screenshot.png");         }     } 
like image 69
Hans Passant Avatar answered Sep 19 '22 03:09

Hans Passant