欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2023-12-17 09:21:10
效果图:        //偶数随机 random evenranm = new ran...

效果图:

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

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

 //偶数随机
  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# 根据表格偶数、奇数加载不同颜色,希望对大家有所帮助

上一篇:

下一篇: