设置“;重要的“-信息为红色,其他为白色
本文关键字:红色 白色 其他 信息 重要的 设置 | 更新日期: 2023-09-27 18:20:41
我正在创建一个日历,我想将重要会议设置为红色,其他会议设置为白色。我怎样才能做到这一点?当我将最后一行的颜色设置为红色时,不重要的会议也是红色的。我的代码:
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
像这样使用Console.ForegroundColor
:
important = Console.ReadLine();
Console.Write("Priority: ");
if (important == "yes" || important == "Yes")
{
Console.ForegroundColor = ConsoleColor.Red ;
important = "Important";
}
else
{
Console.ForegroundColor = ConsoleColor.White;
important = "Normal";
}
Console.Write(important);
检查Arghya C的答案
旧代码:
string important;
Console.Write("'n'nIs the meeting high priority?'n Input '"Yes'" or '"No'": ");
important = Console.ReadLine();
if (important == "yes" || important == "Yes")
{
Console.Write("'nPriority: 't");
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("Important");
}
else
{
Console.Write("'nPriority: 't");
Console.ForegroundColor = ConsoleColor.White;
Console.Write("Normal");
}