C#根據表格偶數與奇數載入不同顏色的執行個體分析

來源:互聯網
上載者:User
這篇文章主要介紹了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添加到控制項

總結

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.