1

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?

Kooki
  • 1,157
  • 9
  • 30
  • 2
    The console can only use 16 distinct colors. You can modify the palette to remap one of those 16 color choices to a different color but if that logical color is already used for text in the console buffer then that's going to change the color of that existing text as well. Use a different Console.ForegroundColor to avoid this. – Hans Passant Mar 05 '14 at 13:53
  • If I understand correct, you mean I can use 16 different colors, but if I need more (maybe 32 or 64), there's no chance to use a color only for one letter, and then change the same color again without recoloring existing letters? – Kooki Mar 06 '14 at 09:50

0 Answers0