|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestConsole.Controls
{
public class Progress
{
public int X { get; set; }
public int Y { get; set; }
public Progress (int x, int y)
{
this.X = x;
this.Y = y;
}
private System.Threading.Thread mainThread;
public void Start()
{
mainThread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(
(object o) =>
{
FireProgress(this.X, this.Y);
}));
mainThread.Start();
}
public void Stop()
{
mainThread.Abort();
Console.BackgroundColor = ConsoleColor.Black;
Console.ForegroundColor = ConsoleColor.Black;
Console.CursorLeft = this.X;
Console.CursorTop = this.Y;
Console.Write(" ");
Console.ForegroundColor = ConsoleColor.Gray;
Console.CursorLeft = 0;
Console.CursorTop = 0;
}
private static void FireProgress(int x, int y)
{
int step = 2;
Console.CursorTop = y;
Console.CursorLeft = x;
Console.ForegroundColor = ConsoleColor.White;
Console.Write("Please wait ");
int k = x + 12;
while (true)
{
Console.CursorTop = y;
Console.CursorLeft = k;
Console.BackgroundColor = (step == 2) ? ConsoleColor.White : ConsoleColor.Black;
Console.Write(" ");
k += step;
System.Threading.Thread.Sleep(100);
if (k > 32 + x)
step = -2;
if (k <= x + 12)
step = 2;
}
}
}
public class Point
{
public int X { get; set; }
public int Y { get; set; }
public Point(int x, int y)
{
this.X = x;
this.Y = y;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.