65.9K
CodeProject is changing. Read more.
Home

Converting HTML Color Code to System.Drawing.Color(WinMobile application)

starIconstarIconstarIconstarIconstarIcon

5.00/5 (4 votes)

Apr 26, 2011

CPOL
viewsIcon

25054

Converting HTML Color Code to System.Drawing.Color(WinMobile application)

I had a scenario where I needed to convert an HTML color code to System.Drawing.Color for using it in Windows Mobile Form application. So how do we do it? It is simple. Well, here we go...
string HTMLColor = "#ffe080";
int RGB = int.Parse(HTMLColor.Replace("#", ""), System.Globalization.NumberStyles.HexNumber);
Color oColor = Color.FromArgb(RGB);
HTML Color code will always be appended with a "#". So first, we need to remove it and convert the Hex color number to integer format. Now we can use inbuilt .NET class functions to convert the integer color value to color code. It can be used like, say we have a text box control. Set the text box foreground color as:
TextBox.ForeColor  = oColor;