Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switching a .NET Core console app into a full-screen mode on Windows 10

In Windows 10, a console app can be switched to a full-screen mode by pressing F11 or Alt+Enter. Note that this is not your grandfather's text-only VGA full-screen mode that was supported before Windows Vista. Although there is no task-bar or title bar visible in this mode, other windows (or Start menu) can pop up on top of it, and it is part of Windows GUI.

I have a .NET Core / C# console app running on Windows 10. When I need to switch it to a full-screen mode, I use P/Invoke to send a F11 keystroke to my own window after bringing it to foreground. Obviously, it does not do what I want if the app has been already switched to a full-screen mode manually before, but I can try to work around it by doing some computations with the window size to detect it.

I am looking for a less round-about way to do it. I would like to know:

  • How do I check from a console app whether it is currently in a full-screen mode?
  • How do I switch my console app to and from a full-screen mode?
like image 896
Vladimir Reshetnikov Avatar asked Jan 12 '20 07:01

Vladimir Reshetnikov


Video Answer


2 Answers

  1. Check full screen
 bool isFullScreen()
{
    return Console.WindowWidth ==Console.LargestWindowWidth &&  Console.WindowHeight ==  Console.LargestWindowHeight;
}
  1. switch to full-screen mode
Console.SetWindowSize(Console.LargestWindowWidth, Console.LargestWindowHeight);
like image 171
MD. RAKIB HASAN Avatar answered Oct 16 '22 01:10

MD. RAKIB HASAN


I am looking for a less round-about way to do it Since full-screen is a feature of GUI layer, trying to use it with console applications will always be kind of round-about

While the other answer describes, how you can run it, in most cases if you need full screen I'd consider creating your own window app (WPF? UWP?) with consolish interface. This way you can fully control the screen, block exiting it etc.

like image 33
karolgro Avatar answered Oct 16 '22 01:10

karolgro