Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert Hexadecimal #FFFFFF to System.Drawing.Color [duplicate]

Tags:

c#

asp.net

Possible Duplicate:
How to get Color from Hex color code using .NET?

I want to convert a string like #FFFFFF to System.Drawing.Color. How do you do that?

like image 356
user1531040 Avatar asked Aug 28 '12 08:08

user1531040


2 Answers

string hex = "#FFFFFF"; Color _color = System.Drawing.ColorTranslator.FromHtml(hex); 

Note: the hash is important!

like image 60
varg Avatar answered Oct 07 '22 00:10

varg


You can do

var color =  System.Drawing.ColorTranslator.FromHtml("#FFFFFF"); 

Or this (you will need the System.Windows.Media namespace)

var color = (Color)ColorConverter.ConvertFromString("#FFFFFF"); 
like image 35
SidAhmed Avatar answered Oct 07 '22 02:10

SidAhmed