8

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?
Vladimir Reshetnikov
  • 11,750
  • 4
  • 30
  • 51
  • 1
    How did your app? I mean if you run your app like `dotnet your_app.dll` from command line, then alt+enter is working in windows 10, just checked. Do you need something different? – Pavel Anikhouski Jan 12 '20 at 08:06
  • As this is specific to Windows, you need to use WINAPI functions. You can find the Console Api functions here: https://learn.microsoft.com/en-us/windows/console/getconsoledisplaymode – iakobski Jan 12 '20 at 08:09
  • @iakobski Thanks, I can check the current mode of the console window using this function. But, apparently, its counterpart `SetConsoleDisplayMode` is not supported and has no effect on Windows 10. – Vladimir Reshetnikov Jan 12 '20 at 23:54
  • 1
    There is a [Github repo](https://github.com/microsoft/terminal) dedicated to the new console functionality, which is probably the right forum to ask if this is supported programmatically yet, and issue a feature request if not ([#288](https://github.com/microsoft/terminal/issues/288) tracks the option to do this at startup, there appears to be no issue for doing it programmatically on demand). – Jeroen Mostert Jan 13 '20 at 11:05
  • @VladimirReshetnikov can I ask you to share your code? – Keyvan Kabirnia Aug 15 '20 at 18:50
  • It is SetConsoleDisplayMode(), the extra unintuitive step to take is to make the screen buffer large enough. [Look here](https://stackoverflow.com/questions/66087598/setconsoledisplaymode-function-is-not-working-setting-my-window-to-fullscreen). What ailed the OP will be forever unknown, do declare the app to be dpiAware. – Hans Passant Oct 15 '21 at 20:23
  • I tried to implement above functionality, even after 3 hours of try I didn't succeed. Even if I add hard coded Top, left, width, height Console starts at (H: 30, W:120). The problem is Console measure its height and width in row, and row count is not at all useful to make console window full screen. Now I doubt even this is possible in .net core 3.1. If it is possible I am happy to pass see it – Prasad Telkikar Oct 22 '21 at 16:47
  • see my answer in [this stackoverflow post](https://stackoverflow.com/questions/4423085/c-sharp-full-screen-console/72596493#72596493) – TechDogLover OR kiaNasirzadeh Jun 12 '22 at 23:13

2 Answers2

4
  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);
MD. RAKIB HASAN
  • 3,670
  • 4
  • 22
  • 35
1

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.

karolgro
  • 181
  • 1
  • 8