console project question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there any way to do that C# always writes in the same line of the console?
 
Console.SetCursorPosition method in .NET 2.0.

Not sure about 1.x though.

Glenn
 
sgr said:
Is there any way to do that C# always writes in the same line of the
console?

Use a carriage return:

Console.Out.Write( "\r" + TextToWrite );

Cleaning the line for previous output is left as an exercise for the reader
:-)

Ebbe
 
sgr,

..NET 2.0 Console class has new method for controlling the caret position. I
believe you can use this to position the caret at the begining of the line
you want to rewrite. In 1.x thought this method doesn't exist, however you
can use the ASCII control symbols to move the caret. Originally these
symbols are meant to be used to control a printer devices, thus the names
doesn't fit well with the conception of the screen:
- CR (carriage return) - 0xD ('\r') moves the caret at the beginning of the
line
- LF (line feed) - 0xA ('\n') moves the caret on the next line (same column
thought); this is the reason microsoft used two characters for new line -
"\r\n"
- BS (backspace) - 0x8 ('\b') - move the caret one position ot the left
- HT (horizontal tab) 0x9 ('\t') - move the caret one tabulation on the
right.

You can use thought to control the caret position on the console window.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top