console.write easy peasy beginners question

  • Thread starter Thread starter simonl
  • Start date Start date
S

simonl

I'm messing about with a console app that does some tedious data
processing, I want to show activity in the console window.

What I wanted was -
followed by \
followed by |

etc;

ie a bar revolving on the spot

console.write advances the character position by one though

Can I send a backspace through? (Have tried .write(8) .write 0x08
which is ascii BS but it keeps printing the number...)

Ta.
 
I'm messing about with a console app that does some tedious data
processing, I want to show activity in the console window.

What I wanted was -
followed by \
followed by |

etc;

ie a bar revolving on the spot

console.write advances the character position by one though

Can I send a backspace through? (Have tried .write(8) .write 0x08
which is ascii BS but it keeps printing the number...)

Ta.

I've done the same exact thing before. It was a while ago, but I think
I moved the cursor back by using the Console.CursorLeft method.
 
To elaborate, before you start drawing your spinning cursor, you will
want to store the location of the cursor using the static CursorLeft and
CursorTop properties on the Console class.

After you write your character, you will want to call the static
SetCursorPosition method on the Console class, setting the location to the
values you obtained before, and then write your character again.
 
simonl said:
Can I send a backspace through? (Have tried .write(8) .write 0x08
which is ascii BS but it keeps printing the number...)

You can cast a number to char. So it would be:
..Write((char)8)

This would write a backspace to the console, though I don't know the exact
effect of this on the console. You will have to try ;)

You also can use character escapes: \b is backspace IIRC.
So '\b' means a backspace char, and "\b" would be a string with a single
backspace character.

Christof
 
To elaborate, before you start drawing your spinning cursor, you will
want to store the location of the cursor using the static CursorLeft and
CursorTop properties on the Console class.

After you write your character, you will want to call the static
SetCursorPosition method on the Console class, setting the location to the
values you obtained before, and then write your character again.


Luvverly, and lots more ascii graphics tools to play with too.
 
Christof Nordiek said:
You can cast a number to char. So it would be:
.Write((char)8)
This would write a backspace to the console, though I
don't know the exact effect of this on the console.

It works fine. I suppose "\b" is theoretically more portable though.

using System.Threading;
....
while (true) foreach (char ch in new char[] { '|', '\\', '-', '/' })
{
Console.Write(ch + "\b");
Thread.Sleep(100);
}

Eq.
 

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