Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change foreground and background text color in console?

Tags:

c#

colors

console

I'm writing a console C# program. I would like to change the foreground and the background color of the text in console.

like image 790
king9981 Avatar asked Jul 28 '11 13:07

king9981


People also ask

How do you change the color of the text in console?

To change the Foreground Color of text, use the Console. ForegroundColor property in C#.

How do I change the color of my console background?

ConsoleColor[] colors = (ConsoleColor[]) ConsoleColor. GetValues(typeof(ConsoleColor)); // Save the current background and foreground colors. ConsoleColor currentBackground = Console. BackgroundColor; ConsoleColor currentForeground = Console.

How do I change the background color of my console in C++?

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.

How do I change the background color of text in C#?

To change the background color of text in Console, use the Console. BackgroundColor Property in C#.


2 Answers

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.
like image 143
Jalal Said Avatar answered Oct 11 '22 14:10

Jalal Said


You need only to set

Console.BackgroundColor = ConsoleColor.Blue;
Console.ForegroundColor = ConsoleColor.Red;

Read all about it at http://www.dotnetperls.com/console-color

like image 22
stimms Avatar answered Oct 11 '22 14:10

stimms