英文:
Can't change terminal window size in C# Console
问题
我正在尝试使用Console.SetWindowSize()来更改C#控制台应用程序的窗口大小。在以前的Visual Studio版本或Windows版本中,这是有效的。但现在不起作用。
重现步骤:
-
在Windows 11、Visual Studio 2019中创建一个新的C#控制台应用程序(.NET Framework)。
-
将以下代码添加到主函数中:
Console.SetWindowSize(10, 10);
Console.WriteLine("Hello world");
Console.ReadLine();
- 运行代码。我得到以下结果。
我看到了这个答案,建议更改终端输出模式。我尝试在Visual Studio 2019的设置搜索栏中使用Environment > Terminal来设置终端输出,分别选择了Developer Command Prompt和Ubuntu WSL终端,但都不能调整控制台窗口的大小。
是否有解决方案?
英文:
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:
-
In Windows 11, Visual Studio 2019, create a new C# Console App (.NET Framework) application
-
Add the code to the main function:
Console.SetWindowSize(10, 10);
Console.WriteLine("Hello world");
Console.ReadLine();
- Run the code. I get the following result.
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.
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
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();
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论