private void MainForm_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; int cellLength = gridLength / game.NumCells; for (int r = 0; r < game.NumCells; r++) { for (int c = 0; c < game.NumCells; c++) { // Get proper pen and brush for on/off grid section Brush brush; Pen pen; if (game.IsLightOn(r, c)) { pen = Pens.Black; brush = Brushes.White; // On } else { pen = Pens.White; brush = Brushes.Black; // Off } // Determine (x,y) coord of row and col to draw rectangle int x = c * cellLength + GridOffset; int y = r * cellLength + GridOffset; // Draw outline and inner rectangle g.DrawRectangle(pen, x, y, cellLength, cellLength); g.FillRectangle(brush, x + 1, y + 1, cellLength - 1, cellLength - 1); } } }