C#控制台程序输出彩色文字
/*
* 由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#控制台程序输出彩色文字的更多相关文章
- echo输出彩色文字
开启转义功能 echo -e表示开启转义功能,比如: 彩色文字语法 echo -e "\e[前景;背景;特效m""hello""\e[0m" ...
- 利用ANSI转义序列在控制台输出彩色文字
说明:无论什么语言,只要你的终端能够解释ANSI转义序列(大多数的类unix终端仿真器都能够解释ANSI转义序列,win32控制台则不支持),就能够使用ANSI转义序列输出颜色.这个功能看似鸡肋,但只 ...
- python 安装 colorama 控制台输出彩色文字
pip install colorama from colorama import Back,Fore,Style # 字体颜色print(Fore.LIGHTBLUE_EX,'HelloWorLd' ...
- (转)Visual Studio控制台程序输出窗口一闪而过的解决方法
背景:熟悉visiual studio工具的使用 刚接触 Visual Studio的时候大多数人会写个Hello World的程序试一下,有的人会发现执行结束后输出窗口会一闪而过,并没有出现Pres ...
- Visual Studio控制台程序输出窗口一闪而过的解决方法
转载大牛的博客,自己也遇到了类似的问题,解决方法很详细,也很管用 刚接触 Visual Studio的时候大多数人会写个Hello World的程序试一下,有的人会发现执行结束后输出窗口会一闪而过 ...
- C#的控制台程序输出
1. int nChar; string mystring; Console.WriteLine("{0} {1}",nChar,mystring); 其中{0},{1}为占位符 ...
- (原+转)ubuntu终端输出彩色文字
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/6066697.html 参考网址: http://www.tuicool.com/articles/jI ...
- day27-控制台输出彩色文字
格式:\033[显示方式;前景色;背景色m 说明:显示方式 意义------------------------- 0 终端默认设置 1 ...
- C# 基础控制台程序的创建,输出,输入,定义变量,变量赋值,值覆盖,值拼接,值打印
基础学习内容有 Console.WriteLine("要输出的内容");//往外输出内容的 Console.ReadLine(); //等待用户输入,按回车键结束,防止程序闪退 控 ...
随机推荐
- Python中xlrd和xlwt模块读写Excel的方法
本文主要介绍可操作excel文件的xlrd.xlwt模块.其中xlrd模块实现对excel文件内容读取,xlwt模块实现对excel文件的写入. 着重掌握读取操作,因为实际工作中读取excel用得比较 ...
- js new关键字
实现new 关键字只需4步 1. 声明一个对象: 2. 把这个对象的__proto__ 指向构造函数的 prototype; 3. 以构造函数为上下文执行这个对象: 4. 返回这个对象. 简洁的代码示 ...
- 谈谈Java引用和Threadlocal的那些事
1 背景 某一天在某一个群里面的某个群友突然提出了一个问题:"threadlocal的key是虚引用,那么在threadlocal.get()的时候,发生GC之后,key是否是null?&q ...
- BZOJ 2039 [2009国家集训队]employ人员雇佣 网络流
链接 BZOJ 2039 题解 这题建图好神,自己瞎搞了半天,最后不得不求教了企鹅学长的博客,,,,发现建图太神了!! s向每个人连sum(e[i][x]) 的边,每个人向T连a[i]的边.两两人之间 ...
- Python3中的编码问题
编码方式介绍 我们首先来熟悉一下常见的一些编码方式,按照时间轴来划分,共有以下几种编码方式(常见): ASCII编码方式:对127个常见字符进行编码,其中包含了10个阿拉伯数字,共52个大小写英文字母 ...
- 51nod 1577 异或凑数
思路真的是挺巧妙的. 让我惊叹,原来线性基还能这么做?!?! 好吧,这种取若干个数异或凑数的题目怎么能少的了线性基呢? 但是,问题集中在于怎么快速提取一个区间的线性基 暴力n^2 线段树维护线性基?分 ...
- adb相关基础知识集锦
Android单元测试adb shell am instrument -w adb shell dumpsys adb logcat介绍
- MySQL-->高级-->001-->MySQL备份与恢复测试
- net.sf.json------json解析
下载地址 [plain] view plain copy 本次使用版本:http://sourceforge.net/projects/json-lib/files/json-lib/json-l ...
- 使用Python的turtle(海龟)模块画图
第一步:让Python引入turtle模块,引入模块就是告诉Python你想要用它. import turtle 第二步:创建画布.调用turtle中的Pen函数 t = turtle.Pen() 第 ...