[C#] 纯文本查看 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// ColorTo 的摘要说明
/// 三种颜色格式的转换
/// </summary>
public class ColorTo
{
/// <summary>
/// [颜色:16进制转成RGB]
/// </summary>
/// <param name="strColor">设置16进制颜色(#FFFFFF) </param>
/// <returns></returns>
public static System.Drawing.Color ColorToColor(string strHxColor)
{
return System.Drawing.Color.FromArgb(System.Int32.Parse(strHxColor.Substring(1, 2), System.Globalization.NumberStyles.AllowHexSpecifier), System.Int32.Parse(strHxColor.Substring(3, 2), System.Globalization.NumberStyles.AllowHexSpecifier), System.Int32.Parse(strHxColor.Substring(5, 2), System.Globalization.NumberStyles.AllowHexSpecifier));
}
/// <summary>
/// [颜色:System.Drawing.Color 转 #FFFFFF]
/// </summary>
/// <param name="colorp"></param>
/// <returns></returns>
public static string ColorToColor(System.Drawing.Color colorp)
{
return System.Drawing.ColorTranslator.ToHtml(colorp);
}
/// <summary>
/// [颜色:RGB三色数值转换 System.Drawing.Color]
/// </summary>
/// <param name="r">Red</param>
/// <param name="g">Green</param>
/// <param name="b">Blue</param>
/// <returns></returns>
public static System.Drawing.Color ColorToColor(int r,int g,int b)
{
return System.Drawing.Color.FromArgb(r, g, b);
}
}