CodeKicks.com
Focus on Microsoft Technologies - Tutorials, Articles, Code Samples.

Tuesday, October 03, 2006

.NET Function to Convert From Hex String to System.Drawing.Color

.NET Function to Convert From Hex String to System.Drawing.Color
private Color HexToColor(string HexVal)
{
if (HexVal.Length != 6)
throw new ArgumentException("HexVal must
be 6 characters in length", "HexVal");

string hRed = HexVal.Substring(0, 2);
string hGreen = HexVal.Substring(2, 2);
string hBlue = HexVal.Substring(4, 2);
Color ReturnVal = Color.FromArgb(Convert.ToInt32(hRed, 16),
Convert.ToInt32(hGreen, 16), Convert.ToInt32(hBlue, 16));
return ReturnVal;
}

Post a Comment