This article mainly introduces C # according to the table even, odd load different colors, the need for friends can refer to the following
:
Even randomized random evenranm = new Random (); Odd stochastic random oddranm = new Random (); string[] Listcolor = new string[] {"#2BB669", "#FF5750", "#39AFEA", "#9A0089", "#00CC6A", "#717FF9", "#4A5459", "#00B7C 3 "," #0078D7 "," #E2AB12 "}; Record form execution/even number set list<string> evennum=new list<string> (); Odd number Set 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]); }}//Assign a value to list list<role_info> list = new list<role_info> (); List. ADD (New Role_info () {role_name= "Super admin"}); List. ADD (New Role_info () {role_name= "Super User"}); List. ADD (New Role_info () {role_name = "teacher"}); List. ADD (New Role_info () {role_name= "Dean"}); List. ADD (New Role_info () {role_name = "headmaster"}); List. ADD (New Role_info () {role_name = "normal User"}); List. ADD (New Role_info () {role_name = "Test"}); List. ADD (New Role_info () {Role_name = "User"}); List. ADD (New Role_info () {role_name = "test User"}); List. ADD (New Role_info () {role_name = "Student"}); List. ADD (New Role_info () {role_name = "Teacher"}); List. ADD (New Role_info () {role_name = "visitor"}); List. ADD (New Role_info () {role_name = "student"}); 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]); }}//Finally adding the button to the control