C#控制台應用程序中輸出彩色字體。本站提示廣大學習愛好者:(C#控制台應用程序中輸出彩色字體)文章只能為提供參考,不一定能成為您想要的結果。以下是C#控制台應用程序中輸出彩色字體正文
作者:雲霏霏
這篇文章主要為大家詳細介紹了C#控制台應用程序中輸出彩色字體的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下本文實例為大家分享了C#控制台輸出彩色字體的具體代碼,供大家參考,具體內容如下
using System; class Example { public static void Main() { // Get a string array with the names of ConsoleColor enumeration members. String[] colorNames = ConsoleColor.GetNames(typeof(ConsoleColor)); // Display each foreground color except black on a constant black background. Console.WriteLine("All the foreground colors (except Black) on a constant black background:"); foreach (string colorName in colorNames) { // Convert the string representing the enum name to the enum value. ConsoleColor color = (ConsoleColor) Enum.Parse(typeof(ConsoleColor), colorName); if (color == ConsoleColor.Black) continue; Console.Write("{0,11}: ", colorName); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = color; Console.WriteLine("This is foreground color {0}.", colorName); // Restore the original foreground and background colors. Console.ResetColor(); } Console.WriteLine(); // Display each background color except white with a constant white foreground. Console.WriteLine("All the background colors (except White) with a constant white foreground:"); foreach (string colorName in colorNames) { // Convert the string representing the enum name to the enum value. ConsoleColor color = (ConsoleColor) Enum.Parse(typeof(ConsoleColor), colorName); if (color == ConsoleColor.White) continue; Console.Write("{0,11}: ", colorName); Console.ForegroundColor = ConsoleColor.White; Console.BackgroundColor = (ConsoleColor) Enum.Parse(typeof(ConsoleColor), colorName); Console.WriteLine("This is background color {0}.", colorName); Console.ResetColor(); } } }
效果圖:
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持。