c#控制台程序怎么实现输出彩色字体
Console.Title = "131"; //设置控制台窗口的标题
Console.ForegroundColor = ConsoleColor.Red; //设置字体颜色为红色
Console.BackgroundColor = ConsoleColor.Green; //设置黑屏为绿屏,即背景颜色
你要函数的话,无非就是
public static void WriteLine(string msg, ConsoleColor forecolor = ConsoleColor.Red, ConsoleColor backcolor=ConsoleColor.Black)
{
Console.ForegroundColor = forecolor;
Console.BackgroundColor = backcolor;
Console.WriteLine(msg);
Console.ForegroundColor = ConsoleColor.Gray;
Console.BackgroundColor = ConsoleColor.Black;
}
调用的时候直接就是WriteLine("hello");//默认为红字
或者WriteLine("hello",ConsoleColor.Green);