How to make a Console Application fullscreen in C#?

Mr.Postal 20 Reputation points
2024-03-24T18:24:07.4766667+00:00

I want to make a Console Application go into fullscreen automatically, similar to how F11/Alt+Enter does it. I am using .Net 6.0/7.0 in C#. I have seen a previous answer by Karen that involves her Repo and Nuget ConsoleHelperLibrary, but I did not understand it. Can someone please explain how to achieve this?

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
10,619 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,376 questions
Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,607 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,249 questions
0 comments No comments
{count} votes

Accepted answer
  1. KOZ6.0 4,810 Reputation points
    2024-03-24T23:20:05.6633333+00:00

    If you don't know how to use nuget, see below. https://learn.microsoft.com/en-us/nuget/consume-packages/install-use-packages-visual-studio

    You can also be achieved with the following code:

    using System;
    using System.Runtime.InteropServices;
    
    class Program
    {
        [DllImport("kernel32.dll", ExactSpelling = true)]
        private static extern IntPtr GetConsoleWindow();
    
        [DllImport("user32.dll")]
        private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
    
        private const int SW_MAXIMIZE = 3;
    
        static void Main(string[] args) {
            IntPtr handle = GetConsoleWindow();
            ShowWindow(handle, SW_MAXIMIZE);
    
            Console.WriteLine("This is a fullscreen console application.");
            Console.ReadLine();
        }
    }
    

1 additional answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more