I'm writing a console C# program. I would like to change the foreground and the background color of the text in console.
To change the Foreground Color of text, use the Console. ForegroundColor property in C#.
ConsoleColor[] colors = (ConsoleColor[]) ConsoleColor. GetValues(typeof(ConsoleColor)); // Save the current background and foreground colors. ConsoleColor currentBackground = Console. BackgroundColor; ConsoleColor currentForeground = Console.
In C++ programming, the default background of the output screen is black and the text color is the white color, the task is to color both the background and text color in the output screen. console_color = GetStdHandle(STD_OUTPUT_HANDLE); // P is color code according to your need.
To change the background color of text in Console, use the Console. BackgroundColor Property in C#.
Console.BackgroundColor//t set the background color for the text.
Console.ForegroundColor//to set the foreground color for the text.
Console.ResetColor();//set back the foreground color and background color to the default.
You need only to set
Console.BackgroundColor = ConsoleColor.Blue;
Console.ForegroundColor = ConsoleColor.Red;
Read all about it at http://www.dotnetperls.com/console-color
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With