Making a Form that has only one instance

  • Thread starter Thread starter Sumit
  • Start date Start date
S

Sumit

Can any one Please tell me how to write a code to make a
form that has only one instance. Like in Visual Basic 6.0
 
Hi,

You could try something like this.

Public Class Form2
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "


Private Shared instance As Form2

Public Shared ReadOnly Property DefInstance() As Form2
Get
If instance Is Nothing Then instance = New Form2
Return instance
End Get
End Property
End Class

To use

Dim frm As Form2 = Form2.DefInstance
frm.ShowDialog()

Ken
 
* "Sumit said:
Can any one Please tell me how to write a code to make a
form that has only one instance. Like in Visual Basic 6.0

How did you do that in VB6?

BTW: Singleton design pattern.
 
add don't forget to set your constructor as private...


private sub New()
end sub
 
Back
Top