Capture screen:
Rectangle r = system. Windows. Forms. Screen. primaryscreen. bounds;
Image IMG = new Bitmap (R. Width, R. Height );
Graphics G = graphics. fromimage (IMG );
G. copyfromscreen (new point (0, 0), new point (0, 0), new size (R. Width, R. Height ));.
Intptr Dc = G. gethdc ();
G. releasehdc (DC );
G. Dispose ();
IMG. Save ("C: a.jpg ");
Or
Private Static extern bool bitblt (intptr hdcdest, int nxdest, int nydest, int nwidth, int nheight, intptr hdcsrc, int nxsrc, int nysrc, int32 dwrop );
Private image catchscreen ()
{
Bitmap bmpcatched = new Bitmap (this. tablelayoutpanel1.width + 1, this. tablelayoutpanel1.height + 1 );
Graphics G = graphics. fromimage (bmpcatched );
System. Drawing. Rectangle rect = new system. Drawing. rectangle (10, 10,500,400 );
G. copyfromscreen (new point (this. left + this. tablelayoutpanel1.location. X + 7, this. tablelayoutpanel1.location. Y + (panelregisted. height-tablelayoutpanel1.height)/2-1), new point (0, 0), this. panelregisted. clientrectangle. size );
G. drawrectangle (new pen (color. Black), 0, 0, bmpcatched. Width-1, bmpcatched. Height-1 );
Image image = bmpcatched;
Return image;
}
Save the form or control:
Rectangle r = screen. primaryscreen. bounds;
Bitmap BMP = new Bitmap (R. Width, R. Height );
This. drawtobitmap (BMP, R );
BMP. Save ("D:/aa.jpg ");
Note: Both forms and controls use the drawtobitmap method (fw2.0 or above ).