Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In a .NET console app, is it possible to have a line of text stay visible in the console all the time?

Tags:

c#

vb.net

console

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
like image 850
arc Avatar asked Jun 01 '11 21:06

arc


2 Answers

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

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

like image 76
Reed Copsey Avatar answered Oct 11 '22 12:10

Reed Copsey


If you don't intend to run full screen, you could just use Console.Title.

like image 31
comecme Avatar answered Oct 11 '22 13:10

comecme