SoFunction
Updated on 2025-03-07

C# Example of implementing winform screenshot and saving

IntPtr hdcDest, //   Target   DC handle
                    int nXDest,
                    int nYDest,
                    int nWidth,
                    int nHeight,
IntPtr hdcSrc, //    The handle to the source DC
                    int nXSrc,
                    int nYSrc,
System.Int32 dwRop      //   Processing value of the grating
                      );
  private   void   button1_Click(object   sender,      e)  
  {  
//Get the current screen size
  Rectangle   rect   =   new   Rectangle   (   )   ;  
  rect   =      (   this   )   ;  
//Create an image with the current screen as a template
  Graphics   g1   =      (   )   ;  
//Create a bitmap with screen size as standard
  Image   MyImage   =   new   Bitmap   (      ,      ,   g1   )   ;  
  Graphics   g2   =      (   MyImage   )   ;  
//Get the DC of the screen
  IntPtr   dc1   =      (   )   ;  
//Get the DC of Bitmap
  IntPtr   dc2   =      (   )   ;  
//Calling this API function to implement screen capture
  BitBlt   (   dc2   ,   0   ,   0   ,      ,      ,   dc1   ,   0   ,   0   ,   13369376   )   ;  
//Release the DC on the screen
     (   dc1   )   ;  
//Release the DC of Bitmap
     (   dc2   )   ;  
//Save in JPG file format
     (   @"c:/"   ,      );  
(   "The current screen has been saved as a file of disk C!"    )   ;
  }