替代的方法来最大化控制台窗口 - C#控制台、方法来、窗口

2023-09-03 05:50:03 作者:春天的猫

我要创建一个原型一块的功能,我将实现在一个应用程序,特别是我从收集的数据显示在控制台窗口,但不幸的是一些线路的跨度比控制台的默认宽度更宽窗口。

I'm creating a prototype for a piece of functionality that I will be implementing in an application, specifically I am displaying data from a collection to the console window but unfortunately some of the lines span wider than the default width of the console window.

我已经做了一点挖掘和发现,要增加窗口的宽度,唯一的办法就是挖成的Kernel32.dll并手工完成。

I've done a bit of digging and found that the only way to increase the width of the window is to dig into the Kernel32.dll and do it manually.

那样优雅PInvoke的是,没有一个短的方式存在,增加了宽度,例如(Console.Width = 300),或正在使用的Kernel32.dll的唯一途径。

As elegant as pInvoke is, does a "shorter" way exist to increase the width e.g. (Console.Width = 300) or is using the Kernel32.dll the only way.

谢谢!

推荐答案

无需编程。创建您的桌面上的程序的快捷方式。用鼠标右键单击它,属性,布局选项卡。调整屏幕缓冲区和窗口大小的Width属性。

No programming is required. Create a shortcut to your program on the desktop. Right-click it, Properties, Layout tab. Adjust the Width property of the screen buffer and window size.

但你可以做到这一点编程也一样,你发现那些Windows API函数都是由控制台类包装为好。例如:

But you can do it programmatically too, those Windows API functions you found are wrapped by the Console class as well. For example:

    static void Main(string[] args) {
        Console.BufferWidth = 100;
        Console.SetWindowSize(Console.BufferWidth, 25);
        Console.ReadLine();
    }