![]() ![]() Int irc = SetScreenColorsApp.SetScreenColors(screenTextColor, screenBackgroundColor) ĭebug.Assert(irc = 0, "SetScreenColors failed, Win32Error code = " + irc + " = 0x" + irc.ToString("x")) ĭebug.WriteLine("LargestWindowHeight=" + Console.LargestWindowHeight + " LargestWindowWidth=" + Console.LargestWindowWidth) ĭebug.WriteLine("BufferHeight=" + Console.BufferHeight + " WindowHeight=" + Console.WindowHeight + " BufferWidth=" + Console.BufferWidth + " WindowWidth=" + Console.WindowWidth) Irc = SetColor(ConsoleColor.Black, backgroundColor) Īnd then if you want to use Orange or any other color you can do a simple call to SetScreenColor static void Main(string args)Ĭolor screenBackgroundColor = Color.Black Irc = SetColor(ConsoleColor.Gray, foregroundColor) Public static int SetScreenColors(Color foregroundColor, Color backgroundColor) If (hConsoleOutput = INVALID_HANDLE_VALUE)īool brc = GetConsoleScreenBufferInfoEx(hConsoleOutput, ref csbe) Ĭsbe.darkMagenta = new COLORREF(r, g, b) īrc = SetConsoleScreenBufferInfoEx(hConsoleOutput, ref csbe) IntPtr hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE) // 7 Public static int SetColor(ConsoleColor color, uint r, uint g, uint b)ĬONSOLE_SCREEN_BUFFER_INFO_EX csbe = new CONSOLE_SCREEN_BUFFER_INFO_EX() Ĭsbe.cbSize = (int)Marshal.SizeOf(csbe) // 96 = 0圆0 Return SetColor(consoleColor, targetColor.R, targetColor.G, targetColor.B) Public static int SetColor(ConsoleColor consoleColor, Color targetColor) The default console colors used are gray (foreground) and black (background) Set a specific console color to an RGB color Private static extern bool SetConsoleScreenBufferInfoEx(IntPtr hConsoleOutput, ref CONSOLE_SCREEN_BUFFER_INFO_EX csbe) Private static extern bool GetConsoleScreenBufferInfoEx(IntPtr hConsoleOutput, ref CONSOLE_SCREEN_BUFFER_INFO_EX csbe) Private static extern IntPtr GetStdHandle(int nStdHandle) Internal static readonly IntPtr INVALID_HANDLE_VALUE = new IntPtr(-1) // per WinBase.h ![]() Internal struct CONSOLE_SCREEN_BUFFER_INFO_EXĬonst int STD_OUTPUT_HANDLE = -11 // per WinBase.h Using System.Drawing // for Color (add reference to ) Modified by MercuryP with color specifications You will need to do some PINVOKE work but I was easily able to get orange, or any other RGB color into console. That Doesn't give you access to more colors but does lead in the correct direction. Get the working project files off my public Repoīut on further investigation you can do a lot of work to combine red and yellow to get orange. I believe are the only supported colors in console. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |