using System;
namespace console_color_on_demand
{
class Console_Color
{
Type type = typeof (ConsoleColor);
string sampleText;
string color;
string defaultColor = "White";
public Console_Color()
{
sampleText = "Sample text here!";
color = "White";
}
public void GetData()
{
Console.WriteLine("Enter a string!");
sampleText = Console.ReadLine();
Console.WriteLine("Choose a color:\n1.\tRed\n2.\tYellow\n3.\tDarkBlue\n4.\tDarkGreen\n5.\tDarkCyan\n6.\tDarkRed \n7.\tDarkMagenta\n8.\tDarkYellow\n9.\tGray\n10.\tDarkGray\n11.\tGreen\n12.\tCyan\n13.\tMagenta \n14.\tWhite (default)\n");
int choice = Convert.ToInt32(Console.ReadLine());
GetColorTextData(choice);
Console.WriteLine("Do you want to make this color default?\n1.\tYes\n2.\tNo\n");
int ans = Int32.Parse(Console.ReadLine());
if (ans == 1)
{
defaultColor = color;
}
DisplayTextInColor();
defaultTextColor();
Console.WriteLine("Press Ctrl+C to exit");
Console.ReadKey();
Console.Clear();
}
void defaultTextColor()
{
Console.ForegroundColor = (ConsoleColor) Enum.Parse(type, defaultColor);
}
void DisplayTextInColor()
{
Console.ForegroundColor = (ConsoleColor) Enum.Parse(type, color);
Console.WriteLine(sampleText);
Console.ResetColor();
}
void GetColorTextData(int choices)
{
switch (choices)
{
case 1:
color = "Red";
break;
case 2:
color = "Yellow";
break;
case 3:
color = "DarkBlue";
break;
case 4:
color = "DarkGreen";
break;
case 5:
color = "DarkCyan";
break;
case 6:
color = "DarkRed";
break;
case 7:
color = "DarkMagenta";
break;
case 8:
color = "DarkYellow";
break;
case 9:
color = "Gray";
break;
case 10:
color = "DarkGray";
break;
case 11:
color = "Green";
break;
case 12:
color = "Cyan";
break;
case 13:
color = "Red";
break;
case 14:
color = "Magenta";
break;
default:
color = "White";
break;
}
}
}
class Program
{
static void Main(string[] args)
{
var c1 = new Console_Color();
while (true)
{
c1.GetData();
}
}
}
}This code gives user option to enter a string of his/her choice and select a color to display that string in.