0

Hello,

I am in a process of making an adventure text-based game and I was wondering if it's possible to change the text color on the go. What I mean is that normally, your text would be white, but when you advance in the story (e.g. advance on lines), the old lines would get grey color.

Is it even possible to change the color of the lines already printed in console?

Thanks for any help.

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by nick.crane
0

This code snippet should help you do what you want.

int x = Console.CursorLeft;
int y = Console.CursorTop;
ConsoleColor initColour = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("This is white Text");
Console.ForegroundColor = initColour;
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
Console.SetCursorPosition(x,y);
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("This is yellow Text");
Console.ForegroundColor = initColour;
Console.WriteLine("Press any key to continue...");
Console.ReadKey();

Edited by nick.crane: Modified to use SetCursorPosition

0

I just realized I posted it to the wrong forum by mistake. I write in C++ not in C# .. non the less, isn't this VC++ code? I am kinda new to whole this, correct me, if I am wrong. Thanks anyway

0

In a CLR Console Application my original code snippet looks like this.

int x = Console::CursorLeft;
int y = Console::CursorTop;
ConsoleColor initColour = Console::ForegroundColor;
Console::ForegroundColor = ConsoleColor::White;
Console::WriteLine("This is white Text");
Console::ForegroundColor = initColour;
Console::WriteLine("Press any key to continue...");
Console::ReadKey();
Console::SetCursorPosition(x,y);
Console::ForegroundColor = ConsoleColor::Yellow;
Console::WriteLine("This is yellow Text");
Console::ForegroundColor = initColour;
Console::WriteLine("Press any key to continue...");
Console::ReadKey();

And works just the same.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.