无法在C#控制台中更改终端窗口大小。

huangapple go评论200阅读模式
英文:

Can't change terminal window size in C# Console

问题

我正在尝试使用Console.SetWindowSize()来更改C#控制台应用程序的窗口大小。在以前的Visual Studio版本或Windows版本中,这是有效的。但现在不起作用。

重现步骤:

  1. 在Windows 11、Visual Studio 2019中创建一个新的C#控制台应用程序(.NET Framework)。

  2. 将以下代码添加到主函数中:

Console.SetWindowSize(10, 10);
Console.WriteLine("Hello world");
Console.ReadLine();
  1. 运行代码。我得到以下结果。

无法在C#控制台中更改终端窗口大小。

我看到了这个答案,建议更改终端输出模式。我尝试在Visual Studio 2019的设置搜索栏中使用Environment > Terminal来设置终端输出,分别选择了Developer Command Prompt和Ubuntu WSL终端,但都不能调整控制台窗口的大小。

无法在C#控制台中更改终端窗口大小。

是否有解决方案?

英文:

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.

无法在C#控制台中更改终端窗口大小。

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.

无法在C#控制台中更改终端窗口大小。

Is there a solution?

答案1

得分: 1

请调整以下设置

以下是控制台输出

static void Main(string[] args)
{
    Console.WindowHeight = 20;
    Console.WindowWidth = 20;
    Console.WriteLine("Test 1");
    Console.WriteLine("最大高度: " + Console.LargestWindowHeight.ToString());
    Console.WriteLine("最大宽度: " + Console.LargestWindowWidth.ToString());
    Console.ReadKey();
    Console.Clear();
    Console.SetWindowSize(10, 10);
    Console.WriteLine("Test 2");
    Console.WriteLine("最大高度: " + Console.LargestWindowHeight.ToString());
    Console.WriteLine("最大宽度: " + Console.LargestWindowWidth.ToString());
    Console.ReadKey();
    Console.Clear();
}
英文:

Please adjust the following settings

无法在C#控制台中更改终端窗口大小。

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();
    }

无法在C#控制台中更改终端窗口大小。

huangapple
  • 本文由 发表于 2023年7月18日 06:15:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76708406.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定