'How do I get this painting event to work?

I'm trying to create a procedure that will draw all of the squares (and later pieces) for a chess board in a starting position, but I only want it to draw these images once so that I can update the images regularly (representing that a piece has moved or been taken). The reason why I'm not using the following code is because I cannot remove the images when a piece needs to be updated.

Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint

End Sub

I'm not really 100% sure how to do this but this is what I've got so far:

Private Sub SetUpBoard(e As PaintEventArgs)

For i = 0 To 7 'This is the math behind generating the board colours in the right positions.
    For j = 0 To 7
        Board(0, i, j).sSquarePosition = Chr(j + 1) & (i + 1)
        If (j + 97) Mod 2 = (i + 1) Mod 2 Then
            Board(0, i, j).oSquareImage = My.Resources.bSquare
        Else
            Board(0, i, j).oSquareImage = My.Resources.wSquare
        End If
        e.Graphics.DrawImage(Board(0, i, j).oSquareImage, (i * 50) + 1, (j * 50) + 1) 'Loads the images in the correct positions.
    Next
Next

End Sub

I've probably done this completely wrong but I'd like to know now rather than later, if that's okay. Thanks.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source