K
K
KolasAdsas2015-12-06 19:11:49
.NET
KolasAdsas, 2015-12-06 19:11:49

How to fill a square with random colors?

How to fill a square with random colors? Just so that not the whole square is of the same solid color, as it turns out with this code

Graphics gr; 
            gr = this.CreateGraphics();
            Random r = new Random();
            SolidBrush mySolidBrush = new SolidBrush(Color.FromArgb(r.Next(255),r.Next(255),r.Next(255),r.Next(255)));
            gr.FillRectangle(mySolidBrush, 50, 50, 450, 200);

And that there would be many small squares in one large one, such as a palette of colors in paint, but not that they would be randomly scattered.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Filatov, 2015-12-07
@NYMEZIDE

something like this

foreach(int x=50; x < 450; x++)
foreach(int y=50; y < 200; y++)
{
SolidBrush mySolidBrush = new SolidBrush(Color.FromArgb(r.Next(255),r.Next(255),r.Next(255),r.Next(255)));
gr.FillRectangle(mySolidBrush, x, y, x+1, y+1);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question