Use Custom Console Colors

ぃ、小莉子 提交于 2020-01-11 11:19:10

问题


To use different colors than provided via ConsoleColor I implemented code you can find on p/invoke here. This solution works fine, I can use every color/colorcode I want to visualize. But CONSOLE_SCREEN_BUFFER_INFO_EX only contains a few different colors. If I changed for example ConsoleColor.White to Color.LimeGreen and write text with this color, it'll be recolored, if I change ConsoleColor.White later to another Color. For example:

        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);

Is it possible to changes colors on runtime, without restyling text, which is already visible?

来源:https://stackoverflow.com/questions/22196664/use-custom-console-colors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!