Search code examples
c#visual-studiovisual-studio-2019console-application

Can't change terminal window size in C# Console


I'm trying to use Console.SetWindowSize() to change the window size of the Console, for a C# Console application. In previous versions of Visual Studio or Windows, this would work. Now it does not.

Steps to reproduce:

  1. In Windows 11, Visual Studio 2019, create a new C# Console App (.NET Framework) application

  2. Add the code to the main function:

Console.SetWindowSize(10, 10);
Console.WriteLine("Hello world");
Console.ReadLine();
  1. Run the code. I get the following result.

enter image description here

I've seen this answer which suggests changing the terminal output mode. I tried setting the terminal output using Enviroment > Terminal from the settings search bar in Visual Studio 2019, to either Developer Command Prompt or Ubuntu WSL terminals, but neither allowed resizing the Console window.

enter image description here

Is there a solution?


Solution

  • Please adjust the following settings

    enter image description here

    The following is the console output

        static void Main(string[] args)
        {
            Console.WindowHeight = 20;
            Console.WindowWidth = 20;
            Console.WriteLine("Test 1");
            Console.WriteLine("Max height: " + Console.LargestWindowHeight.ToString());
            Console.WriteLine("Max width: " + Console.LargestWindowWidth.ToString());
            Console.ReadKey();
            Console.Clear();
            Console.SetWindowSize(10, 10);
            Console.WriteLine("Test 2");
            Console.WriteLine("Max height: " + Console.LargestWindowHeight.ToString());
            Console.WriteLine("Max width: " + Console.LargestWindowWidth.ToString());
            Console.ReadKey();
            Console.Clear();
        }
    

    enter image description here