加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C# 根据表格偶数、奇数加载不同颜色

发布时间:2020-12-15 05:48:48 所属栏目:百科 来源:网络整理
导读:效果图: //偶数随机 Random evenRanm = new Random(); //奇数随机 Random oddRanm = new Random(); string[] listColor = new string[] { "#2BB669","#FF5750","#39AFEA","#9A0089","#00CC6A","#717FF9","#4A5459","#00B7C3","#0078D7","#E2AB12" }; //记载

效果图:

      

 //偶数随机
  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 = "学生" }); 
   Button btn=null;
   for (int i = 0; i < list.Count; i++)
   {
    btn = new FButton();
    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]));
     }
   } 
    //最后将Button添加到控件

总结

以上所述是小编给大家介绍的C# 根据表格偶数、奇数加载不同颜色,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程小技巧网站的支持!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读