简体   繁体   English

C#打印到命令提示符时增加命令提示符的长度

[英]C# Increasing Length of Command Prompt when Printing to Command Prompt

Okay so I admit this is a bit of a trivial problem, but I was hoping someone who has done some Windows development knows what I'm talking about here. 好的,我承认这是一个小问题,但是我希望已经进行Windows开发的人知道我在这里说的是什么。

I made a C# code which takes all the words in the clipboard and prints them to the command prompt one on a line, alphabetically sorted (ignoring punctuation). 我编写了一个C#代码,该代码将剪贴板中的所有单词都打印到一行上的命令提示符中,并按字母顺序排序(忽略标点符号)。 HOWEVER, the problem lies in after the program is completed, so you cannot see all the words that were printed. 但是,问题出在程序完成后,所以您看不到所有已打印的单词。 The lines at the top get cut off. 顶部的线被切断。

This only happens with really long strings that have a lot of words, it blows through the available amount of lines you can scroll back up to see in the command prompt so you can't see everything the program printed. 这仅在具有很多单词的非常长的字符串中发生,它会跳过可滚动的可用行数,您可以向上滚动以在命令提示符下查看,从而看不到程序打印的所有内容。

Come to think of it, this is a common problem I've encountered when working with the Windows command prompt. 想一想,这是我在使用Windows命令提示符时遇到的常见问题。

Is there any way to prevent this? 有什么办法可以防止这种情况? Any workarounds? 任何解决方法? I'll continue to fiddle around and see if there is. 我会继续摆弄,看看是否有。

Use Console.SetBufferSize() like this: 像这样使用Console.SetBufferSize()

class Program
{
    static void Main(string[] args)
    {
        Console.SetBufferSize(Console.WindowWidth, 9999);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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