I am having fun with Console Applications and just wanted to know. What's the best way to save the current buffer of a console window for later use and provide a sort of history navigation function. I know the Diagnostics namespace provides ability to read standard output but that's only if you redirect it, so basically you will have to run process all your results in a new window which seems a little dumb.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You need to read the console screen buffer.
I wrote a series of articles about accessing the Console API from .NET a few years ago. The article you're interested in is Working with Console Screen Buffers.
Full source code is available at http://mischel.com/pubs/consoledotnet/consoledotnet.zip.