using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp5
{
public partial class Form1 : Form
{
int[] w, x, y, h;
Color[] color;
private Random rand = new Random();
public Form1()
{
InitializeComponent();
this.ClientSize = new Size(800, 600);
w = new int[50];
x = new int[50];
y = new int[50];
h = new int[50];
color = new Color[50];
}
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < 50; i++)
{
w[i] = rand.Next(20, 150);
h[i] = rand.Next(20, 150);
x[i] = rand.Next(0, this.ClientSize.Width - w[i]);
y[i] = rand.Next(0, this.ClientSize.Height - h[i]);
color[i] = Color.FromArgb(rand.Next(255), rand.Next(255), rand.Next(255));
}
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
for (int i = 0; i < 50; i++)
{
Brush brush = new SolidBrush(color[i]);
g.FillRectangle(brush, x[i], y[i], w[i], h[i]);
}
}
}
}