c# - 设置 "Important"-消息红色,其他白色

标签 c# console-application textcolor

我正在构建一个日历,我想将重要的 session 设置为红色,其他 session 设置为白色。我怎样才能做到这一点?当我将最后一行的颜色设置为红色时,不重要的 session 也是红色的。我的代码:

string important;
Console.Write("High priority? input yes or no: ");
important = Console.ReadLine();

if (important == "yes" || important == "Yes")
{
    important = "Important";
}
else
{
    important = "Normal";
}

Console.Write("Priority: " + important);

最佳答案

如果将 ForeGroundColor 更改为 Red,则必须将其重置为默认颜色 Gray。您可以使用此代码

Console.Write("High priority? input yes or no: ");
string important = Console.ReadLine();

if (important.Equals("yes", StringComparison.InvariantCultureIgnoreCase))
{
    Console.Write("Priority: ");
    Console.ForegroundColor = ConsoleColor.Red; 
    Console.Write("Important");        
}
else
{
    Console.ForegroundColor = ConsoleColor.White;
    Console.Write("Priority: Normal");
}
Console.ResetColor(); //default

关于c# - 设置 "Important"-消息红色,其他白色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33541439/

相关文章:

c# - 将 OpenCV Mat 转换为 Texture2D?

c# - 验证字符串仅包含 C# 控制台应用程序中的字母

c# - 如何从控制台应用程序返回 List<string>?

android - 如何更改微调器文本颜色

twitter-bootstrap - 使用 Twitter Bootstrap,如何自定义一页的 h1 文本颜色,而将其他页面保留为默认颜色?

android - 按下时更改单个 ClickableSpan 的文本颜色,而不影响同一 TextView 中的其他 ClickableSpan

c# - 防止空 Gridview 数据将 "&nbsp;"填充到文本框中

c# - 如何将 gridview 上的复选框值与数据库表的值绑定(bind)?

c# - 列表上的动态查询选择包含列表

c# - 如何从网页中的链接读取 url 参数的内容?