0
    using System;
    class ColorTheText
    {
        public static void Main(string [] args)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("\t\tCongratulations! You have cleared this level. \n\n\t\t\t    Entering Level 2...");
            Console.ForegroundColor = ConsoleColor.White;
        }
    }

But I want to get the color from hex code i.e. ConsoleColor. color from hex code (#c0c0c0). How to do it?

Jonathan Nixon
  • 4,940
  • 5
  • 39
  • 53
Arun Pandey
  • 513
  • 3
  • 6
  • 13
  • [This answer](http://stackoverflow.com/questions/7937256/changing-text-color-in-c-sharp-console-application) says "No hex allowed" for ConsoleColor – Jonesopolis Oct 24 '13 at 13:44
  • error CS0117: 'System.ConsoleColor' does not contain a definition for 'silver' or 'Silver' – Arun Pandey Oct 24 '13 at 13:47
  • @Jonesy That is true. But it is possible. – User 12345678 Oct 24 '13 at 13:47
  • There are only 16 possible colors so you could just hard-code the Color to ConsoleColor mapping with a switch() statement. Do note that the names don't necessarily match the actual color that the user sees. The console window allows remapping the color index to another color. – Hans Passant Oct 24 '13 at 14:05

1 Answers1

0
System.Drawing.ColorTranslator.FromHtml("#c0c0c0");

Something like that is what you need? Perhaps you serve.

Sorry for my english.

Nacho
  • 1,023
  • 1
  • 10
  • 26