How do you make a C# (.NET) console application open full screen?

Sometimes, a windows application can be unnecessary for a small application, especially if it is just a batch application. There are times, though, when you want a Full-Screen Console Application because you want to see the history of what is being processed but do not want the complexity of a windowed application. If you use the below sample, the application will resize to a full screen of the window once it has finished loading. It will open in its standard size and then resize to full screen. The .NET code is in C# but can be easily converted for those who use VB.NET.

Built-in .NET functionality doesn't exist, and you need to call external windows dlls for the function. If you are writing the application so that it can be run on other systems, e.g. Linux, not just for a Windows environment, then this program will not work. There is a command Console.SetWindowsSize, but it won't do what you are hoping.

    using System;
    using System.Runtime.InteropServices;

    namespace ConsoleApplication1
    {
        class Program
        {
            [DllImport("kernel32.dll", ExactSpelling = true)]
            private static extern IntPtr GetConsoleWindow();
            private static IntPtr ThisCon = GetConsoleWindow();

            [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
            private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

             // State of the application once loaded
            private const int HIDE = 0;
            private const int MAXIMIZE = 3;
            private const int MINIMIZE = 6;
            private const int RESTORE = 9;

            static void Main(string[] args)
            {
                ShowWindow(ThisCon, MAXIMIZE);
                Console.ReadLine();
            }
        }
    }

Tags - .NET   Console Application

Last Modified : June 2023


About... / Contact.. / Cookie...