/*
* 由SharpDevelop创建。
* 用户: 从前的我
* 日期: 2012-06-03
* 时间: 21:30
*
* 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
*/
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();
}
}
}

实例:

        static void Main(string[] args)
{
Thread t = new Thread(WriteY); //创建一个新线程
t.Start(); //启动线程 WriteY
//同时,主线程也会执行。
for (int i = 0; i < 1000; i++) WriteLine2("x"); Console.Read();
} static void WriteY()
{
for (int i = 0; i < 1000; i++) { WriteLine("y"); Thread.Sleep(10); }
//Console.Write(Thread.CurrentThread.Name); } //红底白字
public static void WriteLine(string msg, ConsoleColor forecolor = ConsoleColor.White, ConsoleColor backcolor = ConsoleColor.Red)
{
Console.ForegroundColor = forecolor;
Console.BackgroundColor = backcolor;
Console.Write(msg);
//Console.ForegroundColor = ConsoleColor.Red;
//Console.BackgroundColor = ConsoleColor.Yellow;
} //绿底白字
public static void WriteLine2(string msg, ConsoleColor forecolor = ConsoleColor.White, ConsoleColor backcolor = ConsoleColor.DarkYellow)
{
Console.ForegroundColor = forecolor;
Console.BackgroundColor = backcolor;
Console.Write(msg);
//Console.ForegroundColor = ConsoleColor.Red;
//Console.BackgroundColor = ConsoleColor.Green;
}

http://www.cnblogs.com/backkoms/archive/2012/06/03/2533228.html

C#控制台程序输出彩色文字的更多相关文章

  1. echo输出彩色文字

    开启转义功能 echo -e表示开启转义功能,比如: 彩色文字语法 echo -e "\e[前景;背景;特效m""hello""\e[0m" ...

  2. 利用ANSI转义序列在控制台输出彩色文字

    说明:无论什么语言,只要你的终端能够解释ANSI转义序列(大多数的类unix终端仿真器都能够解释ANSI转义序列,win32控制台则不支持),就能够使用ANSI转义序列输出颜色.这个功能看似鸡肋,但只 ...

  3. python 安装 colorama 控制台输出彩色文字

    pip install colorama from colorama import Back,Fore,Style # 字体颜色print(Fore.LIGHTBLUE_EX,'HelloWorLd' ...

  4. (转)Visual Studio控制台程序输出窗口一闪而过的解决方法

    背景:熟悉visiual studio工具的使用 刚接触 Visual Studio的时候大多数人会写个Hello World的程序试一下,有的人会发现执行结束后输出窗口会一闪而过,并没有出现Pres ...

  5. Visual Studio控制台程序输出窗口一闪而过的解决方法

    转载大牛的博客,自己也遇到了类似的问题,解决方法很详细,也很管用   刚接触 Visual Studio的时候大多数人会写个Hello World的程序试一下,有的人会发现执行结束后输出窗口会一闪而过 ...

  6. C#的控制台程序输出

    1. int nChar; string mystring; Console.WriteLine("{0} {1}",nChar,mystring); 其中{0},{1}为占位符 ...

  7. (原+转)ubuntu终端输出彩色文字

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/6066697.html 参考网址: http://www.tuicool.com/articles/jI ...

  8. day27-控制台输出彩色文字

    格式:\033[显示方式;前景色;背景色m 说明:显示方式           意义-------------------------  0             终端默认设置  1         ...

  9. C# 基础控制台程序的创建,输出,输入,定义变量,变量赋值,值覆盖,值拼接,值打印

    基础学习内容有 Console.WriteLine("要输出的内容");//往外输出内容的 Console.ReadLine(); //等待用户输入,按回车键结束,防止程序闪退 控 ...

随机推荐

  1. java数组倒序查找值

    java语言里面没有arr[:-2]这种方式取值 只能通过  arr[arr.length-1-x]的方式取值倒数的 x(标示具体的某个值)

  2. 【刷题】BZOJ 2151 种树

    Description A城市有一个巨大的圆形广场,为了绿化环境和净化空气,市政府决定沿圆形广场外圈种一圈树.园林部门得到指令后,初步规划出n个种树的位置,顺时针编号1到n.并且每个位置都有一个美观度 ...

  3. 认清Android框架 MVC,MVP和MVVM

    编者按:现在很多时候,我们都是面向搜索(或 Google 或百度).GitHub 编程,那么,在早期没有互联网的情况下,该如何学习编程,成为一名真正的开发者?亦或是作为一名小白,如何进入互联网编程时代 ...

  4. D. Recovering BST Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)

    http://codeforces.com/contest/1025/problem/D 树 dp 优化 f[x][y][0]=f[x][z][1] & f[z+1][y][0] ( gcd( ...

  5. shell中exec命令

    1.find中的-exec参数 在当前目录下(包含子目录),查找所有txt文件并找出含有字符串"bin"的行 find ./ -name "*.txt" -ex ...

  6. Hadoop实战:Hadoop分布式集群部署(一)

    一.系统参数优化配置 1.1 系统内核参数优化配置 修改文件/etc/sysctl.conf,使用sysctl -p命令即时生效.   1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...

  7. vue+webpack开发(三)

    上一篇博文讲了怎么使用路由,这次主要讲讲怎么编写一个vue组件 vue定义了一种“单文件组件”后缀为‘.vue’的文件,大概长这样子: <template> <div> < ...

  8. HDU 3537 基础翻硬币模型 Mock Turtles 向NIM转化

    翻硬币游戏,任意选3个,最右边的一个必须是正面.不能操作者败. 基本模型..不太可能自己推 还是老实记下来吧..对于单个硬币的SG值为2x或2x+1,当该硬币的位置x,其二进制1的个数为偶数时,sg= ...

  9. lua元表详解

    元表的作用 元表是用来定义对table或userdata操作方式的表 举个例子 local t1 = {1} local t2 = {2} local t3 = t1 + t2 我们直接对两个tabl ...

  10. chrome 隐藏技能之 base64 图片转换

    有时候我们要转换图片为base64,或者将base64转回图片,可能都需要找一些在线工具或者软件类型的工具才行.当然 chrome 也算是软件,但是好在做前端的都有 chrome.好了,来看下简单的例 ...