I just finished my C# console application code for a project and would like to add some color to my font. I would love to be able to use a custom color - orange. Is there any way to do this?
This is the code I have been using to change colors in the past, but it doesn't offer orange:
Console.ForegroundColor = ConsoleColor.Magenta(and so on);
Is there a way to maybe insert a hex value for the color or something similar?
It does not orange because that color is not one of the supported color for console. I mean, you can not get it even using windows API. If you want to verify it, take a look at the following piece of code:
a bit late, i know. But one way to achieve colors that are normally not available in C# Console is to change the ColorCode of a color in the Registry. But be warned, this is propably the most unacceptable way to do it. Just open regedit (Win + R, then type "regedit"), go to HKEY_CURRENT_USER, open the key "Console" (At this point you should export the "Console" Key to restore it later). There you will see a list of values from ColorTable00 to ColoTable15. if you change, lets say, ColorTable10 from 0x0000ff00 to 0x0000a5ff (or 65280 to 42495) you will have an orange color when you use ConsoleColor.Green in the Console after restarting it. You can also change this value by code
Of course that works with all other ColorTable-Values and Colorcodes but it is changed only for your User on your PC.
The console API does not support custom colors.
You could do it via the UI (right-click the console titlebar, Settings, Colors)
Expanding on the answer of Alexei Shcherbakov Windows 10 ENABLE_VIRTUAL_TERMINAL_PROCESSING here is a complete color code mapping so you have all colors and their respective numbers in one place:
The list found at http://msdn.microsoft.com/en-us/library/system.console.backgroundcolor.aspx
I believe are the only supported colors in console. No hex allowed.
EDIT
Get the working project files off my public Repo
https://bitbucket.org/benskolnick/color-console/
But on further investigation you can do a lot of work to combine red and yellow to get orange. Follow the example here. Not going to re-post wall of code. http://support.microsoft.com/kb/319883That Doesn't give you access to more colors but does lead in the correct direction. You will need to do some PINVOKE work but I was easily able to get orange, or any other RGB color into console. http://pinvoke.net/default.aspx/kernel32.SetConsoleScreenBufferInfoExAnd then if you want to use Orange or any other color you can do a simple call to SetScreenColor
[Shameless self-promotion]
I'm working on a project that allows you to style console output in any System.Drawing.Color, including orange. Here's how you'd do it:
Console.WriteLine("writing to the console in orange", Color.Orange);
Project: http://colorfulconsole.com/