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(); //等待用户输入,按回车键结束,防止程序闪退 控 ...
随机推荐
- 新版 Chrome Ajax 跨域调试
一.前言 web 开发中 Ajax 是十分常见的技术,但是在前后端使用接口对接的调试过程中不可避免会碰到跨域问题.今天我给大家介绍一个十分简单有效的方法. 跨域经典错误 二.Chrome 跨域设置 首 ...
- Tether USDT 节点钱包的安装与使用
当前,在进行数字资产交易的过程中,由于各国政府的政策因素,法币成为数字资产交易的一个重要问题.在法币接入数字资产交易的过程中,通常是用某种数字资产对法币进行锚定,例如bitshares上面的许多b ...
- java 23种设计模式 深入浅出
以下内容只作为对自己对知识进行总结,如有引用他人文章会在文段末尾表明出处: Java的23种设计模式 23种设计模式总共可以分为三大类,进行不定期更新总结,将逐步展开介绍自己对设计模式的理解,多多指教 ...
- Valid BFS? CodeForces - 1037D(思维 bfs)
我真是一只菜狗......emm... 题意: 判断一个从1开始的队列是否可以按照bfs的顺序 进行遍历..必须从1开始...然后后边依次是bfs顺序 解析: 看代码能看懂吧...emm...就是把每 ...
- Codeforces 817
A 你可以按如下方式移动 问能不能从给定的一个坐标走到另一个. [solution] 裸,奇偶性注意 #include<stdio.h> #include<stdlib.h> ...
- 超实用Image类
using System; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Runt ...
- 使用alien命令让deb包和rpm包互相转换
OS version: CentOS7 / Debian9 发现alien这个命令时很惊喜,之前在debian上安装etcd找不到安装包感觉很不科学,有了alien命令事情一下就变简单了. 这里以et ...
- Hadoop生态圈-Kafka的旧API实现生产者-消费者
Hadoop生态圈-Kafka的旧API实现生产者-消费者 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.旧API实现生产者-消费者 1>.开启kafka集群 [yinz ...
- bzoj千题计划291:bzoj3640: JC的小苹果
http://www.lydsy.com/JudgeOnline/problem.php?id=3640 dp[i][j] 表示i滴血到达j的概率 dp[i][j] = Σ dp[i+val[i]][ ...
- Linux命令(六)Linux超级用户和管理组
修改文件目录的所属组