Hello Kodeeswaran,
When you use GDI Objects(Brush, Bitmap, Font and so on) and declare them in the scope of the Form class, you need to correctly dispose of the object before the form is closed (disposed).
For example:
Public Class Form1
Private pen As Pen = New Pen(Color.Red)
Private Sub panelPaint_Paint(ByVal sender As Object, ByVal e As PaintEventArgs)
e.Graphics.DrawRectangle(pen, New Rectangle(10, 10, 100, 100))
End Sub
Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As FormClosedEventArgs)
pen.Dispose()
End Sub
End Class
Besides, our forum is about the usage of tools and editors in Visual Studio, and Visual Basic forum is currently not supported in the Microsoft Q&A forums, I recommend you can redirect and post a new thread to our MSDN Visual Basic forum.
Best Regards,
Tianyu