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#基于OLEDB获取Excel文件表结构信息的方法
栏 目:C#教程
本文标题:C#控制台应用程序中输出彩色字体
本文地址:https://www.xiuzhanwang.com/a1/C_jiaocheng/5723.html
您可能感兴趣的文章
- 01-10C#通过反射获取当前工程中所有窗体并打开的方法
- 01-10C#实现Winform中打开网页页面的方法
- 01-10C#实现由四周向中心缩小的窗体退出特效
- 01-10Extjs4如何处理后台json数据中日期和时间
- 01-10C#中DataGridView常用操作实例小结
- 01-10C#编程获取资源文件中图片的方法
- 01-10C#使用windows服务开启应用程序的方法
- 01-10asp.net中XML如何做增删改查操作
- 01-10C#利用反射技术实现去掉按钮选中时的边框效果
- 01-10C#中查找Dictionary中的重复值的方法
阅读排行
本栏相关
- 01-10C#通过反射获取当前工程中所有窗体并
- 01-10关于ASP网页无法打开的解决方案
- 01-10WinForm限制窗体不能移到屏幕外的方法
- 01-10WinForm绘制圆角的方法
- 01-10C#实现txt定位指定行完整实例
- 01-10WinForm实现仿视频 器左下角滚动新
- 01-10C#停止线程的方法
- 01-10C#实现清空回收站的方法
- 01-10C#通过重写Panel改变边框颜色与宽度的
- 01-10C#实现读取注册表监控当前操作系统已
随机阅读
- 08-05DEDE织梦data目录下的sessions文件夹有什
- 08-05织梦dedecms什么时候用栏目交叉功能?
- 04-02jquery与jsp,用jquery
- 01-10C#中split用法实例总结
- 01-11ajax实现页面的局部加载
- 01-10使用C语言求解扑克牌的顺子及n个骰子
- 01-10SublimeText编译C开发环境设置
- 01-10delphi制作wav文件的方法
- 01-11Mac OSX 打开原生自带读写NTFS功能(图文
- 08-05dedecms(织梦)副栏目数量限制代码修改