颜色转换方法:
/// <summary> /// 颜色转换函数 /// </summary> /// <param name="colorName">#141452</param> /// <returns>颜色</returns> public static System.Drawing.Color ToColor(string colorName) { if (colorName.StartsWith("#")) colorName = colorName.Replace("#", string.Empty); int v = int.Parse(colorName, System.Globalization.NumberStyles.HexNumber); return System.Drawing.Color.FromArgb( Convert.ToByte((v >> 24) & 255), Convert.ToByte((v >> 16) & 255), Convert.ToByte((v >> 8) & 255), Convert.ToByte((v >> 0) & 255) ); }
使用时:
Button1.BackColor = ToColor("#148ea4");