Changing console output color

October 22, 2011 § 1 Comment


Recently I have been learning git and have was intrigued with their use of color in the console output. (You also experience this when you run msbuild). Anyway it turns out this is actually really easy to do in your own console applications. Here is the code that produces the output you see in the image.

static void Main(string[] args)
{
    Console.ForegroundColor = ConsoleColor.Red;
    Console.WriteLine("Red");
    Console.ForegroundColor = ConsoleColor.Yellow;
    Console.WriteLine("Yellow");
    Console.ForegroundColor = ConsoleColor.Green;
    Console.WriteLine("Green");
    Console.ResetColor();
    Console.WriteLine("Normal");
    Console.ReadLine();
}
About these ads

§ One Response to Changing console output color

  • Jayson Rowe says:

    Very awesome. I have never looked into much in the way of customization on the Windows CLi before, outside of changing the default font. There are lots of things you can do with colors with Bash also…almost too much, actually.

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 )

Connecting to %s

What’s this?

You are currently reading Changing console output color at Jamey McElveen.

meta

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: