Change Background color on C# console application

This question already has an answer here:

  • How do I change the full background color of the console window in C#? 3 answers

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


    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;
    


    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();
    
            }
        }
    }
    
    链接地址: http://www.djcxy.com/p/87418.html

    上一篇: 更改整个控制台背景颜色(Win32 C ++)

    下一篇: 在C#控制台应用程序上更改背景颜色