Http://www.cnblogs.com/goldarch/archive/2010/08/16/1801053.html
#region [color: 16 binary to RGB]
<summary>
[Color: 16 binary to RGB]
</summary>
<param name= "Strcolor" > Set 16 binary color [return rgb]</param>
<returns></returns>
public static System.Drawing.Color Colorhx16torgb (String strhxcolor)
{
Try
{
if (Strhxcolor.length = = 0)
{//If empty
Return System.Drawing.Color.FromArgb (0, 0, 0);//Set to Black
}
Else
{//Convert color
Return System.Drawing.Color.FromArgb (System.Int32.Parse (strhxcolor.substring (1, 2), System.Globalization.NumberStyles.AllowHexSpecifier), System.Int32.Parse (Strhxcolor.substring (3, 2), System.glob Alization. Numberstyles.allowhexspecifier), System.Int32.Parse (Strhxcolor.substring (5, 2), System.Globalization.NumberStyles.AllowHexSpecifier));
}
}
Catch
{//Set to Black
Return System.Drawing.Color.FromArgb (0, 0, 0);
}
}
#endregion
#region [color: RGB to 16 binary]
<summary>
[Color: RGB to 16 binary]
</summary>
<param name= "R" > Red int</param>
<param name= "G" > Green int</param>
<param name= "B" > Blue int</param>
<returns></returns>
public static string colorRGBtoHx16 (int R, int G, int B)
{
Return System.Drawing.ColorTranslator.ToHtml (System.Drawing.Color.FromArgb (R, G, B));
}
#endregion
and
private string Tohexcolor (color color)
{
String R = convert.tostring (color. R, 16);
if (R = = "0")
R = "00";
String G = convert.tostring (color. G, 16);
if (G = = "0")
G = "00";
String B = convert.tostring (color. B, 16);
if (B = = "0")
B = "00";
String hexcolor = "#" + R + G + B;
return hexcolor;
}
public string ForeColor
{
Set
{
Value = #ab364f
int r = Convert.ToInt32 ("0x" + value. Substring (1, 2), 16);
int g = Convert.ToInt32 ("0x" + value. Substring (3, 2), 16);
int B = Convert.ToInt32 ("0x" + value. Substring (5, 2), 16);
Txturl.forecolor = System.Drawing.Color.FromArgb (r,g,b);
}
}
C # RGB vs. 16 binary Color Conversion method