To take a screenshot in C#, you can use the Graphics.CopyFromScreen
method. This method allows you to copy the contents of the screen to a bitmap. You can then save or display the bitmap as needed.
Here's an example of how to take a screenshot:
main.cs456 chars12 lines
Note that this code will take a screenshot of the entire screen. If you only want to take a screenshot of a specific window or region of the screen, you'll need to adjust the CopyFromScreen
parameters accordingly.
Additionally, if you want to copy the screenshot to the clipboard instead of saving it to a file, you can use the Clipboard.SetImage
method:
main.cs32 chars2 lines
gistlibby LogSnag