简体   繁体   中英

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

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.

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

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

mode 120,60

will resize the console window to 120 columns and 60 lines

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 :

控制台截图

 system("mode 45, 20"); 

This is a bad solution because it disables vertical scrolling.

This is better:

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

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

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

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

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.

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. "

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).

now when running Cygwin always gives me a large window.

Windows 7 64bit.

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.

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)

@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.

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.

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

在此输入图像描述

在此输入图像描述

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

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 size of 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.

The same things apply for Windows PowerShell

Click on the icon on the top left of the console frame (the one that looks like "C:\\"), then select Properties . This lets you customize all kinds of stuff. The "layout" tab has the width of the window.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM