Click here to Skip to main content
12,500,761 members (47,139 online)
Click here to Skip to main content
Add your own
alternative version

Stats

16.7K views
5 bookmarked
Posted

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

, 29 Apr 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
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;

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Midhunlal G
Unicel Technologies
India India
.Net developer by job. C developer by passion.

You may also be interested in...

Pro
Pro

Comments and Discussions

 
Questionoptimize Pin
Shargon_855-Aug-11 22:44
memberShargon_855-Aug-11 22:44 
AnswerRe: optimize Pin
Midhunlal G6-Aug-11 4:01
memberMidhunlal G6-Aug-11 4:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160919.1 | Last Updated 29 Apr 2011
Article Copyright 2011 by Midhunlal G
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid