使用自定义控制台颜色
要使用与ConsoleColor
提供的颜色不同的颜色,我实现了代码,您可以在此处找到p / invoke 。 这个解决方案工作正常,我可以使用我想要的每个颜色/颜色代码。 但CONSOLE_SCREEN_BUFFER_INFO_EX
只包含几种不同的颜色。 如果我将例如ConsoleColor.White
更改为Color.LimeGreen
并使用此颜色编写文本,则会重新着色,如果我稍后将ConsoleColor.White
更改为另一种颜色。 例如:
Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("White text"); //text is white Console.ReadKey(true); ConsoleExtender.SetScreenColors(Color.Goldenrod, Color.Black); Console.WriteLine("Goldenrod text"); //both lines are goldenrod Console.ReadKey(true); ConsoleExtender.SetScreenColors(Color.LimeGreen, Color.Black); Console.WriteLine("LimeGreen text"); //all three lines are limegreen Console.ReadKey(true);
是否可以在运行时更改颜色,而无需重新显示已经可见的文本?