/*
* TestConsole / art at poorcoding dot com
* Testing the .NET Console Framework - A basic demo modified from MSDN examples.
* Get terminal size, set cursor position, set colours, "ansimation", what fun.
*/
using System;
using System.Text;
public class TestConsole
{
protected static int startRow;
protected static int startCol;
protected static void WriteAt(string s, int x, int y)
{
try
{
Console.SetCursorPosition(startCol + x, startRow + y);
Console.Write(s);
}
catch (ArgumentOutOfRangeException e)
{
Console.Clear();
Console.WriteLine(e.Message);
}
}
protected static void Colours(int x, int y)
{
try
{
x = startCol + x;
y = startRow + y;
Console.SetCursorPosition(x, y);
String nl = Environment.NewLine;
String[] colorNames = ConsoleColor.GetNames(typeof(ConsoleColor));
for (int a = 0; a < colorNames.Length; a++)
{
Console.Write("{0,2}: ", a);
Console.BackgroundColor = ConsoleColor.Black;
Console.ForegroundColor = (ConsoleColor)Enum.Parse(typeof(ConsoleColor), colorNames[a]);
Console.Write("Foreground color {0}.", colorNames[a]);
Console.ResetColor();
Console.WriteLine();
y++;
Console.SetCursorPosition(x, y);
}
}
catch (ArgumentOutOfRangeException e)
{
Console.Clear();
Console.WriteLine(e.Message);
}
}
protected static void Anim8(int x, int y)
{
string[] inv = new string[5] { "a", "b", "c", "d", "e" };
for (int a = 0; a < 2; a++)
{
foreach (string s in inv)
{
WriteAt(s, x, y);
System.Threading.Thread.Sleep(100);
}
}
}
public static void Main()
{
Console.Clear();
startRow = Console.CursorTop;
startCol = Console.CursorLeft;
WriteAt(Console.WindowWidth + "x" + Console.WindowHeight, 0, 0);
Colours(15, 3);
Anim8(70, 20);
String quitString = "press key to quit.";
WriteAt(quitString, Console.WindowWidth - quitString.Length, Console.WindowHeight - 2);
// press key before quit.
Console.ReadKey();
}
}
There are no comments on this page. [Add comment]