// Author: Allen Gammel
// Email: allen|p-soft|org
Public Shared Function HexToColor(ByVal hexString As String) As Color
Try
Dim r, g, b As Integer
hexString = hexString.Replace("#", Nothing)
If Not hexString.Length = 6 Then
Return Color.Black
End If r = HexToInt(hexString.Substring(0, 2))
g = HexToInt(hexString.Substring(2, 2))
b = HexToInt(hexString.Substring(4, 2))
Return Color.FromArgb(255, r, g, b)
Catch ex As Exception
Debug.WriteLine(ex.ToString)
Return Color.Black
End Try
End Function
Private Shared Function HexToInt(ByVal hexString As String) As Int32
Return Int32.Parse(hexString, System.Globalization.NumberStyles.HexNumber, Nothing)
End Function
Public Shared Function Color2Hex(ByVal clr As Color) As String
Return "#" & clr.ToArgb().ToString("x").Substring(2)
End Function
These snippets helped me alot, maybe they'll help you aswell.