服务器之家

服务器之家 > 正文

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

时间:2022-01-06 13:06     来源/作者:雲霏霏

本文实例为大家分享了c#控制台输出彩色字体的具体代码,供大家参考,具体内容如下

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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#控制台应用程序中输出彩色字体

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

相关文章

热门资讯

蜘蛛侠3英雄无归3正片免费播放 蜘蛛侠3在线观看免费高清完整
蜘蛛侠3英雄无归3正片免费播放 蜘蛛侠3在线观看免费高清完整 2021-08-24
yue是什么意思 网络流行语yue了是什么梗
yue是什么意思 网络流行语yue了是什么梗 2020-10-11
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
2021年耽改剧名单 2021要播出的59部耽改剧列表
2021年耽改剧名单 2021要播出的59部耽改剧列表 2021-03-05
返回顶部