Public Class Form1
Private rect As New Rectangle(0, 0, 12, 30)
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
'Get the area that was previously drawn in.
Dim oldRect As Rectangle = Me.rect
'Move the drawing area.
Me.rect.Offset(10, 70)
'Get the area that is now going to be drawin in.
Dim newRect As Rectangle = Me.rect
'Make each area for invalidation 1 pixel larger than the actual drawing area in every direction
oldRect.Inflate(1, 1)
newRect.Inflate(1, 1)
'Notify the form that the old and new areas require repainting.
Me.Invalidate(oldRect)
Me.Invalidate(newRect)
'Tell the form to repaint invalidated areas.
Me.Update()
End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
With e.Graphics
.FillRectangle(Brushes.White, Me.rect)
.DrawRectangle(Pens.White, Me.rect)
End With
End Sub
End Class