Found only the answer, how to do it in an application with Windows Forms , here is this code:

Graphics graph = null; var bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); graph = Graphics.FromImage(bmp); graph.CopyFromScreen(0, 0, 0, 0, bmp.Size); bmp.Save("filename"); 

But if you add it to the console application, then Graphics , Bitmap , Screenshot are not perceived (underlined by a red wavy line) . By adding

 using System.Windows.Forms; 

I got rid of problems with Graphics and Bitmap , but the Screen in the second line is still not perceived by the program. How can I take a screenshot of the console application?

  • And there simply transfer the dimensions of the console window and everything. I think you should not specifically your size. There is a standard there. - Aqua
  • And if I need the whole screen, not just the console? - user321409
  • The question is different. Как ΠΌΠΎΠΆΠ½ΠΎ ΡΠ΄Π΅Π»Π°Ρ‚ΡŒ ΡΠΊΡ€ΠΈΠ½ΡˆΠΎΡ‚ Π² консольном ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΈ? - Aqua
  • I meant that the code is working, if you use it with Windows Forms, and if you insert it into the code of the console application, then it is idle - user321409
  • one
    @SeeSharp - The console does not have the ability to take a screenshot of the screen. Using a graphic library is the most. He opened the namespace, but did not add an assembly. - Alexander Petrov

1 answer 1

So the solution was:

 using System; using System.Windows.Forms; using System.Drawing; namespace Screenshot { class Program { static void Main(string[] args) { Graphics graph = null; var bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); graph = Graphics.FromImage(bmp); graph.CopyFromScreen(0, 0, 0, 0, bmp.Size); bmp.Save("filename.png"); } } } 

Screen was in the System.Windows.Forms

Bitmap and Graphics - in System.Drawing . And this is how I got a screenshot with full capture of the entire screen.

  • Hovering the mouse on the underlined mistake is not destiny? - Alexander Petrov
  • "Class1.Screen () is a method that is not allowed in this context" in both cases - user321409
  • that's all, I just foolishly called the Screen method, I had to change its name - user321409
  • Yes, you need to either change the name of the method, or fully specify the namespace of the Screen class. After all, the name of the method is not always possible to change (it can be hard-coded by the interface). - Alexander Petrov
  • You should not ask a question in the answer. It should be set either separately or clarified in the comments. - Aqua