ColorHelper.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace Uni_Trend.MSO7000X.Common.Helper
  8. {
  9. public static class ColorHelper
  10. {
  11. /// <summary>
  12. /// 混合两个颜色,主要是用于控件禁用后颜色的修改
  13. /// </summary>
  14. /// <param name="cA"></param>
  15. /// <param name="cB"></param>
  16. /// <param name="pA"></param>
  17. /// <returns></returns>
  18. public static Color MixColor(this Color cA, Color cB, int pA = 20)
  19. {
  20. decimal percentA = 1 - (decimal)pA / 100;
  21. decimal R = cA.R - (cA.R - cB.R) * percentA;
  22. decimal G = cA.G - (cA.G - cB.G) * percentA;
  23. decimal B = cA.B - (cA.B - cB.B) * percentA;
  24. return Color.FromArgb((int)R, (int)G, (int)B);
  25. }
  26. /// <summary>
  27. /// 根据当前颜色创建控件禁用颜色
  28. /// </summary>
  29. /// <param name="cA"></param>
  30. /// <param name="pA"></param>
  31. /// <returns></returns>
  32. public static Color MixColor(this Color cA, int pA = 20)
  33. {
  34. Color cB = Color.Gray;
  35. decimal percentA = 1 - (decimal)pA / 100;
  36. decimal R = cA.R - (cA.R - cB.R) * percentA;
  37. decimal G = cA.G - (cA.G - cB.G) * percentA;
  38. decimal B = cA.B - (cA.B - cB.B) * percentA;
  39. return Color.FromArgb((int)R, (int)G, (int)B);
  40. }
  41. }
  42. }