![](/img/trans.png)
[英]How to change Foreground Color of each letter in a string in C# Console?
[英]How to change foreground and background text color in console?
我正在编写一个控制台 C# 程序。 我想更改控制台中文本的前景色和背景色。
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.
你只需要设置
Console.BackgroundColor = ConsoleColor.Blue;
Console.ForegroundColor = ConsoleColor.Red;
Console.ForegroundColor = ConsoleColor.Green;
Console.BackgroundColor = Console.Color.White;
设置控制台文本的前景色:
Console.ForegroundColor = ConsoleColor.Red; // Changes console foreground to red
设置控制台文本的文本背景颜色
Console.BackgroundColor = ConsoleColor.Blue; // Changes console text background to blue
设置实际的控制台背景颜色
// Changes console background color to green
Console.BackgroundColor = ConsoleColor.Green;
Console.Clear();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.