在C#控制台应用程序上更改背景颜色
我搜索过网络,但似乎无法找到解决方案。 我希望我的整个控制台应用程序窗口是特定的颜色,例如蓝色。 我怎么做?
只需设置背景颜色并调用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(); } }
您可以将Console.BackgroundColor
属性设置为ConsoleColor
枚举。
获取或设置控制台的背景颜色。 要更改>控制台窗口的背景颜色,请设置BackgroundColor属性并调用
Clear
方法。
Console.BackgroundColor = ConsoleColor.Blue; Console.Clear();
您可以使用Console.ForegroundColor
属性
获取或设置控制台的前景色。
Console.ForegroundColor = ConsoleColor.Blue;
OP问题是询问如何将整个背景颜色设置为蓝色。 其他样本都没有正确显示。 这是如何做:
namespace ClearConsole { class Program { static void Main(string[] args) { Console.BackgroundColor = ConsoleColor.Blue; Console.Clear(); } } }
Console.ForegroundColor = Color.Blue;
Console.WriteLine("This string is blue!");