C# Write Console App with Colored lines (Command prompt with color lines)


I have this legacy old application which is running its output to console. I wanted to do something really cool rather than just showing everything in white forecolor with black backcolor.

I wrote small function in my console program.cs as –

public static void ColoredConsoleWrite(ConsoleColor color, string text, bool newLine)
{
           ConsoleColor originalColor = Console.ForegroundColor;
            Console.ForegroundColor = color;
            if (newLine)
                       Console.WriteLine(text);
             else
                      Console.Write(text);
               Console.ForegroundColor = originalColor;
}

Then when I wanted to print line in whatever color , i called that function like –

 ColoredConsoleWrite(ConsoleColor.Red ,  ”     Process is being started … “, true);

That’s it…Worked like a charm.. Hope this helps someone…

Happy Coding… 🙂

Advertisements

2 thoughts on “C# Write Console App with Colored lines (Command prompt with color lines)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s