效果圖: 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添加到控制項