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

黄舟
发布: 2017-05-28 10:01:24
原创
2795人浏览过

这篇文章主要为大家详细介绍了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();

  }

 }

}

登录后复制

效果图:

无阶未来模型擂台/AI 应用平台
无阶未来模型擂台/AI 应用平台

无阶未来模型擂台/AI 应用平台,一站式模型+应用平台

无阶未来模型擂台/AI 应用平台 35
查看详情 无阶未来模型擂台/AI 应用平台

以上就是C#控制台应用程序中如何输出彩色字体的详细介绍的详细内容,更多请关注php中文网其它相关文章!

相关标签:
c#
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号