在.NET控制台应用程序中,是否可以使一行文本始终保持在控制台中可见? [英] In a .NET console app, is it possible to have a line of text stay visible in the console all the time?

查看:60
本文介绍了在.NET控制台应用程序中,是否可以使一行文本始终保持在控制台中可见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当时正在考虑向控制台应用程序添加一个简单的带宽监视器,并且我想知道是否有可能始终在控制台窗口中保持一行可见。我可以手动设置一些内容,以将新的控制台输出传递到一种方法中,该方法将获取控制台的内容,清除控制台,在第一行中添加带宽数据,然后将先前信息的每一行重写回控制台,等等。 。但是,这似乎是一个很棘手的方法,而且我只能限制在控制台窗口中一次可见的行数(不滚动)。

I was thinking of adding a simple bandwidth monitor to a console application and I was wondering if it would be possible to keep a line in the console window visible at all times. I could set something up manually to pass new console output into a method that would get the contents of the console, clear the console, add the bandwidth data on the first row, then rewrite each line of previous information back to the console, etc.. but that seems like a really hacky way to go about it, and I'd be limited to the amount of rows visible at once in the console window (no scrolling).

有什么主意吗?有内置功能吗?示例:

Any idea? Any built in functionality for this? Example:

STATS: Downloaded: 2599b, Uploaded: 754b  <- this always stays at the top   
constantly changing text
constantly changing text
constantly changing text
constantly changing text
constantly changing text
constantly changing text
constantly changing text
constantly changing text
constantly changing text
constantly changing text
constantly changing text
constantly changing text


推荐答案

您可以使用控制台类,例如 CursorTop CursorLeft 可以移动光标。如果将光标移动到行的开头,然后使用 Console.Write ,它将覆盖该位置的数据。

You can use the other members of the Console class, such as CursorTop and CursorLeft to "move around" the cursor. If you move the cursor to the beginning of a line, and then use Console.Write, it will "overwrite" the data at that location.

这可以让您创建正在描述的情况(通过移动光标,书写然后向后移动)。

This lets you create situations like you're describing (by moving the cursor, writing, then moving back).

我通常建议您在需要以特定方式显示多个项目时立即使用GUI应用程序。您将拥有更大的灵活性(这可能会更简单)。

That being said, I typically would recommend using a GUI application as soon as you need to have multiple items being presented in a specific manner. You'll have much more flexibility (and it will likely be simpler).

这篇关于在.NET控制台应用程序中,是否可以使一行文本始终保持在控制台中可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆