如何更改 Windows 控制台窗口的宽度?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/190543/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:31:32  来源:igfitidea点击:

How can I change the width of a Windows console window?

windowswindows-xpconsole

提问by Matthew Scharley

Is it possible to programmatically, or otherwise, increase the width of the Windows console window? Or do I need to create a wrapper program that looks and acts like the console somehow? Are there any programs around that do this already? I use Cygwin extensively in my development, and it seems a little ridiculous to me that all console windows in Windows are width limited.

是否可以通过编程或其他方式增加 Windows 控制台窗口的宽度?或者我是否需要创建一个外观和行为类似于控制台的包装程序?是否有任何程序可以做到这一点?我在我的开发中广泛使用 Cygwin,对我来说,Windows 中的所有控制台窗口都有宽度限制似乎有点荒谬。

If it matters at all, I'm running Windows XP.

如果这很重要,我正在运行 Windows XP。

采纳答案by John Millikin

You can increase it manually by right-clicking the tray icon and entering the options dialog.

您可以通过右键单击托盘图标并进入选项对话框来手动增加它。

There are also third-party terminal emulators for Windows, such as Console:

也有适用于 Windows 的第三方终端模拟器,例如Console

Screenshot of Console

控制台截图

回答by

Simply run "mode cols,lines" to change the size of the current console window:

只需运行“mode cols,lines”来改变当前控制台窗口的大小:

mode 120,60

模式 120,60

will resize the console window to 120 columns and 60 lines

将控制台窗口的大小调整为 120 列和 60 行

回答by Sergey

system("mode 45, 20");
system("mode 45, 20");

This is a bad solution because it disables vertical scrolling.

这是一个糟糕的解决方案,因为它禁用了垂直滚动。

This is better:

这个更好:

system("mode CON: COLS=120");

回答by Sergey

There is a window's api function to set the width. Here's a tut on it. http://www.adrianxw.dk/SoftwareSite/Consoles/Consoles6.html

有一个窗口的api函数来设置宽度。简单介绍一下。 http://www.adrianxw.dk/SoftwareSite/Consoles/Consoles6.html

回答by Carl

If you right click on the title bar of a command window and choose properties, you can change widths in the Layout tab

如果右键单击命令窗口的标题栏并选择属性,则可以在“布局”选项卡中更改宽度

回答by DeveloperDan

If you're programming C# here's a method that worked for me (from the bottom of this page)

如果您正在编写 C#,这里有一个对我有用的方法(从本页底部开始)

static void setConsoleSize()
   {
       System.Console.SetWindowPosition(0,0);   // sets window position to upper left
       System.Console.SetBufferSize(200,300);   // make sure buffer is bigger than window
       System.Console.SetWindowSize(122,54);   //set window size to almost full screen 
       //width - maxSet(127,57) (width, height)

       //System.Console.ResetColor(); //resets fore and background colors to default

   }  // End  setConsoleSize()

Quoted from the post: "My maximum console size that I could use was 127 columns and 57 rows because that's all that my screen resolution will allow. Reset your screen resolution and this will change.

引自帖子:“我可以使用的最大控制台大小是 127 列和 57 行,因为这是我的屏幕分辨率所允许的全部。重置您的屏幕分辨率,这会改变。

This is just one of those things that you are going to have to play around with in order for you to get it to display as you like. "

这只是您必须玩弄的东西之一,以便您按照自己的意愿显示它。”

回答by rob

the

mode 

and

system("mode... 

solutions did not work for me and I could not set the layout without getting a access error.

解决方案对我不起作用,我无法在没有访问错误的情况下设置布局。

Fix was to close Cygwin, right click properties on the icon in the start menu and edit layout -> window -> height and then say yes to allowing administrator privileges to save settings. (not run as administrator).

修复方法是关闭 Cygwin,右键单击开始菜单中图标上的属性并编辑布局 -> 窗口 -> 高度,然后说是以允许管理员权限保存设置。(不以管理员身份运行)。

now when running Cygwin always gives me a large window.

现在运行 Cygwin 时总是给我一个大窗口。

Windows 7 64bit.

视窗 7 64 位。

回答by sepang

To get all future console windows in a specific size you can create a shortcut to cmd.exe and then set size on the layout-tab of the shortcut properties.

要以特定大小获取所有未来的控制台窗口,您可以创建 cmd.exe 的快捷方式,然后在快捷方式属性的布局选项卡上设置大小。

回答by kgiannakakis

In console properties at the Layout tab you can configure the following:

在布局选项卡的控制台属性中,您可以配置以下内容:

Screen Buffer Size Width

屏幕缓冲区大小宽度

Window Size Width

窗口大小宽度

The Window Size Width is how many characters per line will be visible. The Screen Buffer Size is the sizeof the line. If you set for example the Window Size Width at 100 and the Screen Buffer Size Width at 200, you will need to use the scrollbar to view the whole contents of lines with sizes between 100 and 200. Lines longer than 200 characters will appear in more than one line. This is useful if you have long lines and you want to copy them in a text file.

窗口大小宽度是每行可见的字符数。屏幕缓冲区大小是size行的。例如,如果将窗口大小宽度设置为 100,将屏幕缓冲区大小宽度设置为 200,则需要使用滚动条查看大小在 100 到 200 之间的行的全部内容。超过 200 个字符的行将出现在更多比一行。如果您有很长的行并且想要将它们复制到文本文件中,这将非常有用。

The same things apply for Windows PowerShell

同样的事情也适用于 Windows PowerShell

回答by James

Hey have you guys here ever thought of the possibility of launching and running Cygwin from within the windows command prompt/console? This is what I always do. Then you can do anything you want to the look of the console to make it sexy.

嘿,你们这里有没有想过从 Windows 命令提示符/控制台中启动和运行 Cygwin 的可能性?这是我一直在做的。然后你可以对控制台的外观做任何你想做的事情,让它变得性感。

trying to get su from within cygwin can be difficult at times, especially when you are attempting to do some heavy crunching with the tools provided. People have tried all sorts of things from sudo SU for windows to what ever...when it can be as simple as passing on the administrator credentials from you the "user" (if you are the admin?) even without weird UAC pop ups. You can do this via a simple batch script. Have a below this of a screen grab of what my Cygwin looks like and this is running from a portable version of Cygwin too! No registry entries and any of that rubbish!
The batch file passes the credentials to bash and then bash changes directory (notice the double quotes are needed to pass this variable to the Cygwin colsole in order for it to work)

有时尝试从 cygwin 中获取 su 可能很困难,尤其是当您尝试使用提供的工具进行一些繁重的处理时。人们已经尝试了各种各样的东西,从 sudo SU for windows 到任何东西......当它可以像从你的“用户”(如果你是管理员?)传递管理员凭据一样简单时,即使没有奇怪的 UAC 弹出窗口. 您可以通过一个简单的批处理脚本执行此操作。下面是我的 Cygwin 外观的屏幕截图,这也是从 Cygwin 的便携式版本运行的!没有注册表项和任何垃圾!
批处理文件将凭据传递给 bash,然后 bash 更改目录(注意需要双引号将此变量传递给 Cygwin colsole 以使其工作)

@echo off
setlocal enabledelayedexpansion
REM Changing working folder back to current directory
%~d0
CD %~dp0
REM Folder changed
bash --login -i -c "cd {insert_directory_name_here} && exec ./execution-file-here"
cls
exit 1

Note: the brackets like so { } in the above example are NOT included in the batch script. also note that windows CMD window is passing off the string to cygwin to interpret as multiple conditions; cygwin doesn't read the quotes them selves but whats between them. the && is saying change directories and when you do execute the script ./execution-file-here when you get there.

注意:上例中的 { } 之类的括号不包含在批处理脚本中。还要注意,windows CMD 窗口将字符串传递给 cygwin 以解释为多个条件;cygwin 不会自己阅读引号,而是阅读它们之间的内容。&& 是说更改目录,当您到达那里时执行脚本 ./execution-file-here 。

It's a double whammy you can launch a Cygwin or linux like application from within a MS-Windows window and not even type a letter of code or open a console or anything.

这是一个双重打击,您可以从 MS-Windows 窗口中启动 Cygwin 或类似 linux 的应用程序,甚至无需键入代码字母或打开控制台或任何东西。

I keep this batch file inside of the /Cygwin/bin directory and create a Windows shortcut link on the desktop. Within the shortcut I can stylise the cmd shell window. Even go as far as transparency ;-)

我将此批处理文件保存在 /Cygwin/bin 目录中,并在桌面上创建一个 Windows 快捷方式链接。在快捷方式中,我可以对 cmd shell 窗口进行样式化。甚至达到透明度;-)

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明