BuddyJoe
BuddyJoe

Reputation: 71171

.NET - Converting Color Name Strings into System.Drawing.Color

What is the best way to turn strings like "red", "green", "yellow", "aliceblue", etc... into the actual System.Drawing.Color value?

I was looking at reflection and something about that didn't seem right.

Upvotes: 18

Views: 33535

Answers (3)

Moose
Moose

Reputation: 5422

System.Drawing.Color has a static method:

public static Color FromName(string name)

Use it like so:

   Color c = Color.FromName("AliceBlue")

Upvotes: 24

Alex Reitbort
Alex Reitbort

Reputation: 13706

You can use Color.FromName()

Upvotes: 30

DavidN
DavidN

Reputation: 5207

System.Drawing.Color.FromName("Red");

Upvotes: 12

Related Questions