How to convert HTML Color code to RGB color code

The following VB.Net code converts HTML color code to equivalent RGB color code.

Module modMain
  Public Function ConvertHTMLToRGBColor(ByVal sHtmlColor As String) As Color
    'Remove the # if exists
    sHtmlColor = sHtmlColor.Replace("#", "")
    Return Color.FromArgb(System.Convert.ToInt32(sHtmlColor.Substring(0, 2), 16), System.Convert.ToInt32(sHtmlColor.Substring(2, 2), 16), System.Convert.ToInt32(sHtmlColor.Substring(4, 2), 16))
  End Function
End Module

Tested with VS 2008

This entry was posted in VB.Net and tagged .net code, convert HTML color code to RGB color code, html color, rgb color, vb.net code. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>