Draw each of 100 cells with randomly chosen colors

image_pdfimage_print

using System;
using System.Drawing;
using System.Windows.Forms;

public class ColorChips : Form {
public ColorChips() {
Size = new Size(300,300);
Text = “Color Chips”;
}

protected override void OnPaint(PaintEventArgs e) {
Graphics g = e.Graphics;
int h = DisplayRectangle.Height;
int w = DisplayRectangle.Width;
Random r = new Random();

for (int i = 0; i < 10; i++){ for (int j = 0; j < 10; j++) { Color color = Color.FromArgb (r.Next(256), r.Next(256), r.Next(256)); Brush brush = new SolidBrush(color); g.FillRectangle(brush, i*w/10, j*h/10, w/10, h/10); } } base.OnPaint(e); } static void Main() { Application.Run(new ColorChips()); } } [/csharp]

This entry was posted in 2D Graphics. Bookmark the permalink.