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 for business Windows Client for IT Pros User experience Other
Developer technologies .NET Other
Developer technologies Visual Studio Other
Developer technologies C#
0 comments No comments
{count} votes

Accepted answer
  1. KOZ6.0 6,655 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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.