public string GetRandomColor()
{ Random RandomNum_First = new Random((int)DateTime.Now.Ticks); // 对于C#的随机数,没什么好说的 System.Threading.Thread.Sleep(RandomNum_First.Next()); Random RandomNum_Sencond = new Random((int)DateTime.Now.Ticks); // 为了在白色背景上显示,尽量生成深色 int int_Red = RandomNum_First.Next(); int int_Green = RandomNum_Sencond.Next(); int int_Blue = (int_Red + int_Green > ) ? : - int_Red - int_Green; int_Blue = (int_Blue > ) ? : int_Blue;
Color color = Color.FromArgb(int_Red, int_Green, int_Blue);
string strColor = "#" + Convert.ToString(color.ToArgb(), ).PadLeft(, '').Substring(, );
return strColor; }