Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.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.

like image 354
BuddyJoe Avatar asked Feb 23 '09 21:02

BuddyJoe


3 Answers

System.Drawing.Color has a static method:

public static Color FromName(string name)

Use it like so:

   Color c = Color.FromName("AliceBlue")
like image 33
Moose Avatar answered Oct 01 '22 20:10

Moose


You can use Color.FromName()

like image 141
Alex Reitbort Avatar answered Oct 01 '22 18:10

Alex Reitbort


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

like image 38
DavidN Avatar answered Oct 01 '22 20:10

DavidN