How to change foreground and background text color in console?

17,554

Solution 1

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.

Solution 2

You need only to set

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

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

Solution 3

Console.ForegroundColor = ConsoleColor.Green;
Console.BackgroundColor = Console.Color.White;

Solution 4

You should be able to use the following properties (links to MSDN documentation):

Console.BackgroundColor

Console.ForegroundColor

Share:
17,554
king9981
Author by

king9981

Updated on June 04, 2022

Comments

  • king9981
    king9981 about 2 years

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

  • king9981
    king9981 almost 13 years
    So, no need to use the windows API!