What is the best way to pick a random brush from the System.Drawing.Brushes collection in C#?
views:
591answers:
3
+1
A:
An obvious way is to generate a random number and then pick the corresponding brush.
ChrisW
2009-06-18 03:33:10
+8
A:
If you just want a solid brush with a random color, you can try this:
Random r = new Random();
int red = r.Next(0, byte.MaxValue + 1);
int green = r.Next(0, byte.MaxValue + 1);
int blue = r.Next(0, byte.MaxValue + 1);
System.Drawing.Brush brush = new System.Drawing.SolidBrush(Color.FromArgb(red, green, blue));
John JJ Curtis
2009-06-18 03:36:51
First time I see someone using byte.MaxValue...
dkson
2010-09-30 10:14:09
+1
A:
I suggest getting a list of enough sample brushes, and randomly selecting from there.
Merely getting a random colour will yield terrible colours, and you could easily set up a list of maybe 50 colours that you could then use every time you need a random one.
ANeves
2010-06-15 09:54:42