error1408

Hi,

how can i "animate" the Text in the console, so that i can show that something is going on.

e.g.

.

..

...

.

..

...

usw.

You know what i mean I've seen this kind of animation several times, but i don't know how to do that.



Re: .NET Base Class Library How to animate in the console?

Mark Betz

using System;

public class MyClass
{
public static void Main()
{
bool done = false;
int n = 0;
int m = 0;
string waiting = "";

Console.Clear();
Console.WriteLine("
Doing some work");
int line = Console.CursorTop;

while (!done)
{
Console.SetCursorPosition(
0, line);
if ( ++n == 6 )
{
n =
0;
m++;
waiting = "";
Console.Write("
");
}
else
{
waiting += "
.";
Console.Write(waiting);
}
if ( m == 5 ) done = true;
System.Threading.Thread.Sleep(
500);
}
Console.SetCursorPosition(
0, line);
Console.WriteLine("
Done! Press any key to exit.");
Console.ReadKey(
false);
}
}





Re: .NET Base Class Library How to animate in the console?

error1408

Thank you



Re: .NET Base Class Library How to animate in the console?

Mark Betz

By the way, I just noticed that this won't work as copied out of the post. The forum has collapsed the number of spaces in the Console.Write(" ") statement that I used to clear the line. Just make sure there are five spaces in there and it will work. There might be a better way to clear the line, and of course the real trick in anything like this is how to keep updating it while you are actually doing work, instead of just simulating it inline like I did.