So you want convert a .NET color to hex or a hex color to .NET color. Well, its very easy to do this. We won’t have to write lots of code or a special class for it. Thanks to ColorTranslator class. We can convert between these with only 1 line of code. Here’s how its done:
To convert a Hex color to .NET color use this code:
Color color = ColorTranslator.FromHtml("#000000");
For converting a .NET color to Hex color, use thise code:
Color color = Color.FromArgb(0, 100, 50, 100); // Get the hex color string HexColor = ColorTranslator.ToHtml(color);
That was simple & easy. If you have any questions don’t hesitate to leave a comment.
Thanks
hi,
First of all. Thanks very much for your useful post.
I just came across your blog and wanted to drop you a note telling you how impressed I was with the information you have posted here.
simi
Highly impressed, found your post on Ask.Glad I finally tested it out. Unsure if its my Chrome browser,but sometimes when I visit your site, the fonts are really small? Anyway, love your site and will check back.See Ya
does not work for compact framework
Nice looking blog you have here. The theme is awesome, great color combination.