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


本文摘自PHP中文网,作者黄舟,侵删。

这篇文章主要为大家详细介绍了C#控制台应用程序中输出彩色字体的方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了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#控制台应用程序中如何输出彩色字体的详细介绍的详细内容!

相关阅读 >>

详细介绍C#服务器性能监控之性能计数器的代码示例

C#与.net框架之间的关系是什么?C#程序的开发工具

C# winform webbrowser 设置为编辑模式的示例代码

关于C#中方法的阐述

简单介绍C#表达式树expression简单类型比较demo的示例代码

C#是什么,能做些什么?

C#学习记录:编写高质量代码改善整理建议1-3

C# 中虚方法和抽象方法

详细介绍C#读取xml多级子节点

教你用C#检测含有中文字符串的实际长度

更多相关阅读请进入《C#》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...