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);
var r = new Random();
var left = 50;
var top = 50;
var width = 450;
var height = 450;
var squareSize = 5;
using (var gr = this.CreateGraphics())
{
foreach(var x=left; x < width - squareSize; x+=squareSize)
foreach(var y=top; y < height - squareSize; y+=squareSize)
{
using (var randomBrush = new SolidBrush(Color.FromArgb(r.Next(255),r.Next(255),r.Next(255),r.Next(255))))
{
gr.FillRectangle(randomBrush , x, y, x+squareSize, y+squareSize);
}
}
}