How to increase the size of the console window in C#?

我是研究僧i 提交于 2019-12-01 17:38:32

问题


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.

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.

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.

Thanks!


回答1:


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.

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


来源:https://stackoverflow.com/questions/4123055/how-to-increase-the-size-of-the-console-window-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!