C# Custom Colors in Consoles

By | July 18, 2014

Ever wanted to make colored lines in a Console Application? By this I mean, for example something went wrong and shows up “An error occurred! Please try again.”. Let’s say you want only errors be colored red and when sothing succeded it would be green, like “Success!”. It is indeed really simple to get this working as I explain in this post titled “ Custom Colors in Consoles”.

I will make a speciffic example for this post:

  String code = "";

  Console.Write("Enter code to continue: ", Console.ForegroundColor = ConsoleColor.White);
  if (code != "mycode")
      Console.Write("\nFalse Code!", Console.ForegroundColor = ConsoleColor.Red);
      Console.Write("\nSuccess", Console.ForegroundColor = ConsoleColor.Green);

As you have probably noticed I used this:

Console.ForegroundColor = ConsoleColor.Red

And this is basically what changes the color.

I hope this post helped you. Please leave a comment.

2 thoughts on “C# Custom Colors in Consoles

  1. Parker Berceir

    Thank you so much for your effort in writing this post.


Leave a Reply

Your email address will not be published. Required fields are marked *