怎样让控制台背景色与前景色(文字)不断的闪烁?
简单的这样不行啊:Random R = new Random();
int r = 1;
for (int i = 1; i < 1000; i++)
{
Thread.Sleep(500);
r = R.Next(1, 7);
switch (r)
{
case 1:
Console.BackgroundColor = ConsoleColor.Yellow;
Console.ForegroundColor = ConsoleColor.DarkRed;
break;
case 2:
Console.BackgroundColor = ConsoleColor.White;
Console.ForegroundColor = ConsoleColor.Black;
break;
case 3:
Console.BackgroundColor = ConsoleColor.Red;
Console.ForegroundColor = ConsoleColor.Green;
break;
case 4:
Console.BackgroundColor = ConsoleColor.Green;
Console.ForegroundColor = ConsoleColor.Red;
break;
case 5:
Console.BackgroundColor = ConsoleColor.Blue;
Console.ForegroundColor = ConsoleColor.Gray;
break;
case 6:
Console.BackgroundColor = ConsoleColor.Magenta;
Console.ForegroundColor = ConsoleColor.White;
break;
}
}
Console.ReadKey();
麻烦大家帮帮我, 谢谢啦! --------------------编程问答-------------------- refer:http://www.cnblogs.com/txw1958/archive/2012/12/07/csharp-console-color.html --------------------编程问答-------------------- 这个不行啊,它是需要你从键盘上键入回车后才改变颜色,我需要的是控制台不需要接收消息,自己不断变化! --------------------编程问答-------------------- 你就不能自己对那个代码进行一些改造么?
比如:
for (int i = 0; i < 2; i++)//循环两次--------------------编程问答-------------------- 用 ANSI escape sequence
{
Thread.Sleep(1000);
Class2 TextChange = new Class2();
Console.WriteLine("Original Colors");
Console.WriteLine("Press Enter to Begin");
Thread.Sleep(1000);
TextChange.TextColor((int)Class2.Foreground.Green +
(int)Class2.Foreground.Intensity);
Console.WriteLine("THIS TEXT IS GREEN");
Console.WriteLine("Press Enter to change colors again");
Thread.Sleep(1000);
TextChange.TextColor((int)Class2.Foreground.Red +
(int)Class2.Foreground.Blue +
(int)Class2.Foreground.Intensity);
Console.WriteLine("NOW THE TEXT IS PURPLE");
Console.WriteLine("Press Enter to change colors again");
Thread.Sleep(1000);
TextChange.TextColor((int)Class2.Foreground.Blue +
(int)Class2.Foreground.Intensity +
(int)Class2.Background.Green +
(int)Class2.Background.Intensity);
Console.WriteLine("NOW THE TEXT IS BLUE AND BACKGROUND OF IT IS GREEN");
Console.WriteLine("Press Enter change everything back to normal");
Thread.Sleep(1000);
TextChange.ResetColor();
Console.WriteLine("Back to Original Colors");
Console.WriteLine("Press Enter to Terminate");
}
例如
echo ^[[H^[[M^[[L^[[Hoooooxxxxxx
echo ^[[H^[[M^[[L^[[H^[[41mxxxxooooo^[[0m
win32 console + ansicon
https://github.com/adoxa/ansicon
补充:.NET技术 , C#