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

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • DZone
  • Reddit
  • Yahoo! Buzz
  • StumbleUpon
  • LinkedIn
  • Twitter