public enum ConsoleColor { black = 0, darkblue = 1, darkgreen = 2, darkaqua = 3, darkred = 4, purple = 5, brown = 6, grey = 7, darkgrey = 8, blue = 9, green = 10, aqua = 11, red = 12, pink = 13, yellow = 14, white = 15, } [ DllImport("kernel32.dll" )] private static extern long SetConsoleTextAttribute(int hConsoleOutput, int wScreenColors); [ DllImport("kernel32.dll" )] private static extern int GetStdHandle(long nStdHandle); private const int STD_OUTPUT_HANDLE = -11; public static void SetConsoleColors( ConsoleColor forecolor, ConsoleColor backcolor) { int hConsole = GetStdHandle(STD_OUTPUT_HANDLE); backcolor = ( ConsoleColor)(((int )backcolor == 0) ? 256 : ((int)backcolor * 16)); SetConsoleTextAttribute(hConsole, (( int)forecolor | (int )backcolor)); } public static void SetConsoleColors( ConsoleColor forecolor) { int hConsole = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hConsole, ( int)forecolor); }