香蕉视频app

Keep on going never give up.

Let's Go

C#【練習】更改控制臺前景色和背景色

C#Lonely2019-05-20 01:54:15145次0條

Console.BackgroundColor = ConsoleColor.Blue; //設置背景色
Console.ForegroundColor = ConsoleColor.White; //設置前景色,即字體顏色
Console.WriteLine("第一行白藍.");

Console.ResetColor(); //將控制臺的前景色和背景色設為默認值
Console.WriteLine("第二行前景色和背景色設為默認值.");

Console.BackgroundColor = ConsoleColor.Red;
Console.ForegroundColor = ConsoleColor.Blue;
string value = "第三行 紅、藍";
Console.WriteLine(value.PadRight(Console.WindowWidth - value.Length)); //設置一整行的背景色

//顯示出Console中支持的背景色及前景色
Type type = typeof(ConsoleColor);
Console.ForegroundColor = ConsoleColor.White;
foreach (string name in Enum.GetNames(type))
{
    Console.BackgroundColor = (ConsoleColor)Enum.Parse(type, name);
    Console.WriteLine(name);
}

Console.BackgroundColor = ConsoleColor.Black;
foreach (string name in Enum.GetNames(type))
{
    Console.ForegroundColor = (ConsoleColor)Enum.Parse(type, name);
    Console.WriteLine(name);
}

Console.ReadKey();

運行結果:

image.png

暗錨,解決錨點偏移

文章評論

    嘿,來試試登錄吧!