Option Strict On Public Class Form1 Dim oldX, oldY As Integer Dim gdi As GDIWrapper Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim baseImage As Bitmap = New Bitmap(PictureBox1.Width, PictureBox1.Height) PictureBox1.Image = baseImage gdi = New GDIWrapper(baseImage) End Sub Private Sub Form1_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed 'gdi.Dispose() End Sub Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove If e.Button = System.Windows.Forms.MouseButtons.Left Then gdi.DrawLine(Pens.Green, oldX, oldY, e.X, e.Y) End If oldX = e.X oldY = e.Y End Sub Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown If e.Button = System.Windows.Forms.MouseButtons.Right Then gdi.FloodFill(Color.Yellow, New Point(e.X, e.Y)) End If End Sub Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click gdi.Dispose() PictureBox1.Invalidate() gdi = New GDIWrapper(CType(PictureBox1.Image, Bitmap)) End Sub End Class