首页 > Windows开发 > 详细

C# 随机颜色的方法

时间:2016-03-23 15:36:09      阅读:213      评论:0      收藏:0      [点我收藏+]
 1          public string GetRandomColor()
 3         {
 4 
 5             Random RandomNum_First = new Random((int)DateTime.Now.Ticks);
 6 
 7             //  对于C#的随机数,没什么好说的
 8 
 9             System.Threading.Thread.Sleep(RandomNum_First.Next(50));
10 
11             Random RandomNum_Sencond = new Random((int)DateTime.Now.Ticks);
12 
13  
14 
15             //  为了在白色背景上显示,尽量生成深色
16 
17             int int_Red = RandomNum_First.Next(256);
18 
19             int int_Green = RandomNum_Sencond.Next(256);
20 
21             int int_Blue = (int_Red + int_Green > 400) ? 0 : 400 - int_Red - int_Green;
22 
23             int_Blue = (int_Blue > 255) ? 255 : int_Blue;
24             Color color = Color.FromArgb(int_Red, int_Green, int_Blue);
25             string strColor = "#" + Convert.ToString(color.ToArgb(), 16).PadLeft(8, 0).Substring(2, 6);
26             return strColor;
27 
28         } 
29 
30 
31   

 

C# 随机颜色的方法

原文:http://www.cnblogs.com/youchim/p/5311343.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!