Friday, 15 February 2013

c# - Picking random color from array list -



c# - Picking random color from array list -

so, trying create function makes label random color list of colors. code right now:

arraylist colors = new arraylist(); colors.add(color.black); random rcolor = new random(); var randomcolor = rcolor.next(0, colors.count); colortextlabel.forecolor = randomcolor;

but returns error @ lastly line of code saying "cannot implicitly convert type 'int' 'system.drawing.color'"

how done?

you need item @ random index, trying assign int color:

colortextlabel.forecolor = (color)colors[randomcolor];

and not ever utilize arraylist while can utilize generics.

c# random arraylist

No comments:

Post a Comment