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?

4
  • This answer says "No hex allowed" for ConsoleColor Commented Oct 24, 2013 at 13:44
  • error CS0117: 'System.ConsoleColor' does not contain a definition for 'silver' or 'Silver' Commented Oct 24, 2013 at 13:47
  • @Jonesy That is true. But it is possible. Commented Oct 24, 2013 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. Commented Oct 24, 2013 at 14:05

1 Answer 1

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

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

Sorry for my english.

Sign up to request clarification or add additional context in comments.

2 Comments

That will return Color instead of ConsoleColor which is required
You have reason, sorry.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.