给C#控制台特定行加上颜色

31 浏览
0 Comments

给C#控制台特定行加上颜色

编写一个小的命令行工具,希望能够以不同的颜色输出。这是否可能?

admin 更改状态以发布 2023年5月22日
0
0 Comments

class Program
{
    static void Main()
    {
        Console.BackgroundColor = ConsoleColor.Blue;
        Console.ForegroundColor = ConsoleColor.White;
        Console.WriteLine("White on blue.");
        Console.WriteLine("Another line.");
        Console.ResetColor();
    }
}

摘自这里

0
0 Comments

是的。请看这个文章。这里有一个来自那里的例子:

Console.BackgroundColor = ConsoleColor.Blue;
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("White on blue.");

enter image description here

0