您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

C#控制台应用程序中如何输出彩色字体的详细介绍

2024/3/17 23:59:58发布35次查看
这篇文章主要为大家详细介绍了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(); } } }
效果图:
以上就是c#控制台应用程序中如何输出彩色字体的详细介绍的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product