C# 自动调整颜色(加深、变亮)
C# 自动调整颜色(加深、变亮)
C# 全选
public static class Extensions
{
/// <summary>
/// 调整颜色(加深、变亮)
/// </summary>
/// <param name="color">当前颜色</param>
/// <param name="factor">调整因子,加深:value<0, 变亮:value>0, -1.0f <= value <= 1.0f </param>
/// <returns></returns>
public static Color Add(this Color color, float factor)
{
float red = (float)color.R;
float green = (float)color.G;
float blue = (float)color.B;
if (factor < 0)
{
factor = 1 + factor;
red *= factor;
green *= factor;
blue *= factor;
}
else
{
red = (255 - red) * factor + red;
green = (255 - green) * factor + green;
blue = (255 - blue) * factor + blue;
}
if (red < 0) red = 0;
if (red > 255) red = 255;
if (green < 0) green = 0;
if (green > 255) green = 255;
if (blue < 0) blue = 0;
if (blue > 255) blue = 255;
return Color.FromArgb(color.A, (int)red, (int)green, (int)blue);
}
}
按钮背景色加深
C# 全选
var factor = -0.3f; //加深颜色
btn_NewFlow.HighlightColor = theme.ThemeBackColor.Add(factor);
按钮背景色变浅
C# 全选
btn.HighlightColor = theme.ThemeBackColor.Add(0.8f);//颜色变浅
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
csframework.workflow C/S框架网