Change Background color on C# console application [duplicate]

孤街浪徒 提交于 2019-12-28 14:41:32

问题


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?


回答1:


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();
    }
}




回答2:


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();

And you can use Console.ForegroundColor property for

Gets or sets the foreground color of the console.

Console.ForegroundColor = ConsoleColor.Blue;




回答3:


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();

        }
    }
}



回答4:


Console.ForegroundColor = Color.Blue;

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



来源:https://stackoverflow.com/questions/14792066/change-background-color-on-c-sharp-console-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!