当前位置: 移动技术网 > IT编程>开发语言>c# > C#控制台应用程序中输出彩色字体

C#控制台应用程序中输出彩色字体

2019年07月18日  | 移动技术网IT编程  | 我要评论
本文实例为大家分享了c#控制台输出彩色字体的具体代码,供大家参考,具体内容如下 using system; class example { publi

本文实例为大家分享了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();
  }
 }
}

效果图:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网