效果图:
//偶数随机 Random evenRanm = new Random(); //奇数随机 Random oddRanm = new Random(); string[] Listcolor = new string[] { "#2BB669","#FF5750","#39AFEA","#9A0089", "#00CC6A","#717FF9","#4A5459","#00B7C3", "#0078D7","#E2AB12" }; //记载窗体执行 //偶数集合 List<string> evennum=new List<string>(); //奇数集合 List<string> oddNum = new List<string>(); for (int j = 0; j < Listcolor.Count(); j++) { if (j % 2 == 0) { evennum.Add(Listcolor[j]); } else { oddNum.Add(Listcolor[j]); } } //对List赋值 List<Role_Info> List = new List<Role_Info>(); List.Add(new Role_Info() { Role_name= "超级管理员"}); List.Add(new Role_Info() { Role_name= "超级用户" }); List.Add(new Role_Info() { Role_name = "教师" }); List.Add(new Role_Info() { Role_name="院长"}); List.Add(new Role_Info() { Role_name = "校长" }); List.Add(new Role_Info() { Role_name = "普通用户" }); List.Add(new Role_Info() { Role_name = "Test" }); List.Add(new Role_Info() { Role_name = "用户" }); List.Add(new Role_Info() { Role_name = "测试用户" }); List.Add(new Role_Info() { Role_name = "Student" }); List.Add(new Role_Info() { Role_name = "Teacher" }); List.Add(new Role_Info() { Role_name = "游客" }); List.Add(new Role_Info() { Role_name = "学生" }); @R_502_5554@ btn=null; for (int i = 0; i < List.Count; i++) { btn = new F@R_502_5554@(); if (i%2==0) { int even = evenRanm.Next(evennum.Count()); btn.Content=List[i].Role_name; btn.Background = new SolIDcolorBrush((color)colorConverter.ConvertFromString(evennum[even])); } else { int odd = oddRanm.Next(oddNum.Count()); btn.Content=List[i].Role_name; btn.Background = new SolIDcolorBrush((color)colorConverter.ConvertFromString(oddNum[odd])); } } //最后将@R_502_5554@添加到控件总结
以上是内存溢出为你收集整理的C#实现表格隔行换色全部内容,希望文章能够帮你解决C#实现表格隔行换色所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)