You can call Invalidate method inside the Form Resize handler. In addition to this move your code from OnPaint to OnPainBackground to avoid flickering. Check the code modifications.
public checkerboard()
{
Size = new Size(400, 400);
Text = "CheckerBoard";
BackColor = Color.Red;
DoubleBuffered = true;
Resize += new System.EventHandler(this.Form1_Resize);
}
protected override void OnPaintBackground(PaintEventArgs e)
{
Graphics g = e.Graphics;
int h = DisplayRectangle.Height;
int w = DisplayRectangle.Width;
for (int i = 0; i < 8; i = i + 2)
for (int j = 0; j < 8; j = j + 2)
{
Color Black = Color.Black;
Brush brush = new SolidBrush(Black);
g.FillRectangle(brush, i * w / 8, j * h / 8, w / 8, h / 8);
brush.Dispose();
}
for (int i = 1; i < 8; i = i + 2)
for (int j = 0; j < 8; j = j + 2)
{
Color White = Color.White;
Brush brush = new SolidBrush(White);
g.FillRectangle(brush, i * w / 8, j * h / 8, w / 8, h / 8);
brush.Dispose();
}
for (int i = 1; i < 8; i = i + 2)
for (int j = 1; j < 8; j = j + 2)
{
Color Black = Color.Black;
Brush brush = new SolidBrush(Black);
g.FillRectangle(brush, i * w / 8, j * h / 8, w / 8, h / 8);
brush.Dispose();
}
for (int i = 0; i < 8; i = i + 2)
for (int j = 1; j < 8; j = j + 2)
{
Color White = Color.White;
Brush brush = new SolidBrush(White);
g.FillRectangle(brush, i * w / 8, j * h / 8, w / 8, h / 8);
brush.Dispose();
}
}
private void Form1_Resize(object sender, EventArgs e)
{
this.Invalidate();
}