生成随机色(深色)
代码
public static Color GetRandomColor()
{
//Random RandomNum_First = new Random((int)DateTime.Now.Ticks);
//System.Threading.Thread.Sleep(100);
//Random RandomNum_Sencond = new Random((int)DateTime.Now.Ticks);
//// 为了在白色背景上显示,尽量生成深色
//int int_Red = RandomNum_First.Next(256);
//int int_Green = RandomNum_Sencond.Next(256);
//int int_Blue = (int_Red + int_Green > 400) ? 0 : 400 - int_Red - int_Green;
//int_Blue = (int_Blue > 255) ? 255 : int_Blue;
//return Color.FromArgb(int_Red, int_Green, int_Blue);
Random RandomNum_First = new Random((int)DateTime.Now.Ticks);
System.Threading.Thread.Sleep(50);
Random RandomNum_Sencond = new Random((int)DateTime.Now.Ticks);
System.Threading.Thread.Sleep(100);
Random RandomNum_Third = new Random((int)DateTime.Now.Ticks);
int y = RandomNum_First.Next(16, 235);
int u = RandomNum_Sencond.Next(16, 240);
int v = RandomNum_Third.Next(16, 240);
int R = (int)(y + 1.14 * v);
int G = (int)(y - 0.394 * u - 0.581 * v);
int B = (int)(y + 2.028 * u);
if (R < 0) R = 0;
if (G < 0) G = 0;
if (B < 0) B = 0;
if (R > 255) R = 255;
if (G > 255) G = 255;
if (B > 255) B = 255;
Color rgb = Color.FromArgb(R, G, B);
return rgb;
}