繁体   English   中英

如何在控制台中更改前景色和背景文字颜色?

[英]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;

http://www.dotnetperls.com/console-color阅读所有相关信息

Console.ForegroundColor = ConsoleColor.Green;
Console.BackgroundColor = Console.Color.White;

您应该能够使用以下属性(指向 MSDN 文档的链接):

控制台.背景颜色

Console.ForegroundColor

设置控制台文本的前景色:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM