Converting HTML Hex Color Codes to RGB in ASP.NET

This is another post for my own remembrance. While working with controls in ASP.NET most of the back colors use the RGB color references instead of allowing you to quickly plug in the Hexadecimal numbers to the control.  At first glance this looks to be a daunting task as there doesn’t appear to be a quick solution for this within the Color class in either VB.NET or C#. But the solution is pretty simple

VB.NET Example

  1: MyControl.BackColor = ColorTranslator.FromHtml("#FFFFFF")

C# Example

  1: MyControl.BackColor = ColorTranslator.FromHtml("#FFFFFF");

It actually becomes pretty easy after you find it.  There are some pretty elegant solutions to this problem on the NET but a lot of them don’t take advantage to what Microsoft has already built into the .NET Framework.

Technorati Tags: ,,,

Posted on 9/24/2008 9:03:25 AM by admin

Permalink | Comments (0) | Post RSSRSS comment feed |

Categories: ASP.NET | C# | Programming | VB.NET

Tags: , , ,

Comments are closed