Change Background color on C# console application

2019-01-18 14:13发布

This question already has an answer here:

Ive searched the Web, but i cant seem to find the solution. I want my whole console application window to be a specific color, for example blue. How do I do that?

4条回答
手持菜刀,她持情操
2楼-- · 2019-01-18 14:28

You can set Console.BackgroundColor property to ConsoleColor enumeration..

Gets or sets the background color of the console. To change the background color of the > console window as a whole, set the BackgroundColor property and call the Clear method.

Console.BackgroundColor = ConsoleColor.Blue;
Console.Clear();

enter image description here

And you can use Console.ForegroundColor property for

Gets or sets the foreground color of the console.

Console.ForegroundColor = ConsoleColor.Blue;

enter image description here

查看更多
倾城 Initia
3楼-- · 2019-01-18 14:30
Console.ForegroundColor = Color.Blue;

Console.WriteLine("This string is blue!");

查看更多
趁早两清
4楼-- · 2019-01-18 14:36

The OP question was asking for how to set the entire background color to blue. None of the other samples shows this correctly. Here's how:

namespace ClearConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.BackgroundColor = ConsoleColor.Blue;
            Console.Clear();

        }
    }
}
查看更多
戒情不戒烟
5楼-- · 2019-01-18 14:38

Simply set the background color and call Console.Clear():

class Program {
    static void Main(string[] args) {
        Console.BackgroundColor = ConsoleColor.Blue;
        Console.Clear();
        Console.ForegroundColor = ConsoleColor.White;
        Console.Write("Press any key to continue");
        Console.ReadKey();
    }
}

enter image description here

查看更多
登录 后发表回答