如何在C#中增加控制台窗口的大小? [英] How to increase the size of the console window in C#?

查看:691
本文介绍了如何在C#中增加控制台窗口的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为将要在应用程序中实现的功能创建原型,特别是我正在将集合中的数据显示到控制台窗口,但是不幸的是,其中一些行的宽度大于控制台的默认宽度窗口。

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函数也由Console类包装。例如:

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

这篇关于如何在C#中增加控制台窗口的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆