using NPOI.SS.Formula.Functions; using System.Diagnostics.Metrics; namespace HStation.WinFrmUI.PhartRelation { public class ColorHelper { public static System.Drawing.Color GetRandomColor() { Random random = new Random(); int red = random.Next(0, 256); int green = random.Next(0, 256); int blue = random.Next(0, 256); Color randomColor = Color.FromArgb(red, green, blue); return randomColor; } public static System.Drawing.Color GetDarkerColor() { Random randomNum_1 = new Random(Guid.NewGuid().GetHashCode()); System.Threading.Thread.Sleep(randomNum_1.Next(1)); int int_Red = randomNum_1.Next(255); Random randomNum_2 = new Random((int)DateTime.Now.Ticks); int int_Green = randomNum_2.Next(255); Random randomNum_3 = new Random(Guid.NewGuid().GetHashCode()); int int_Blue = randomNum_3.Next(255); int_Blue = (int_Red + int_Green > 380) ? int_Red + int_Green - 380 : int_Blue; int_Blue = (int_Blue > 255) ? 255 : int_Blue; return GetDarkerColor(System.Drawing.Color.FromArgb(int_Red, int_Green, int_Blue)); } private static List _color_array = new List() { Color.Red, Color.Blue, Color.Green,Color.DodgerBlue, Color.Fuchsia, Color.MidnightBlue, Color.Maroon, Color.Aquamarine, Color.Bisque,Color.BurlyWood }; public static System.Drawing.Color GetDarkerColor(int index) { if (index < _color_array.Count) { return _color_array[index]; } return GetDarkerColor(); } //获取加深颜色 public static Color GetDarkerColor(Color color) { const int max = 255; int increase = new Random(Guid.NewGuid().GetHashCode()).Next(30, 255); //还可以根据需要调整此处的值 int r = Math.Abs(Math.Min(color.R - increase, max)); int g = Math.Abs(Math.Min(color.G - increase, max)); int b = Math.Abs(Math.Min(color.B - increase, max)); return Color.FromArgb(r, g, b); } } }