How to change Screen buffer size in Windows Command Prompt from batch script

后端 未结 14 1507
清歌不尽
清歌不尽 2020-12-02 09:59

I know you can do right click properties ->layout and there change it manually.

But how would you go about changing it from a Windows batch script?

I know yo

14条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-02 10:25

    Below is a very simple VB.NET program that will do what you want.

    It will set the buffer to 100 chars wide by 1000 chars high. It then sets the width of the window to match the buffer size.

    Module ConsoleBuffer
      Sub Main()
        Console.WindowWidth = 100
        Console.BufferWidth = 100
        Console.BufferHeight = 1000
      End Sub
    End Module
    

    UPDATE

    I modified the code to first set Console.WindowWidth and then set Console.BufferWidth because if you try to set Console.BufferWidth to a value less than the current Console.WindowWidth the program will throw an exception.

    This is only a sample...you should add code to handle command line parameters and error handling.

提交回复
热议问题