Hi,
I usually add a definstance property of a form if I only want
one instance of the form. I would call Form1.DefInstance.Show to display
the form.
Add to the forms new procedure
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
frm = Me
End Sub
Add to the forms dispose procedure
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
frm = Nothing
MyBase.Dispose(disposing)
End Sub
Add the following code to the form
Private Shared frm As Form1
Public Shared ReadOnly Property DefInstance() As Form1
Get
If frm Is Nothing Then frm = New Form1
Return frm
End Get
End Property
Ken
--------------------
"Michael" <Mi*****@discussions.microsoft.com> wrote in message
news:8A**********************************@microsof t.com...
Hi Everyone,
I'm looking for a way to make sure that only one instance of a form is
loaded. I have tried the following:
Private Sub mnuPatients_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuPatients.Click
try
if not ifrmPatients is nothing then
exit Sub
End If
cursor = cursors.WaitCursor
ifrmPatients = new frmPatients
ifrmPatients.MdiParent = me
ifrmPatients.Show
cursor = cursors.Default
Catch ex As Exception
msgbox(ex.Message )
End try
End Sub
That didn't seem to work by itself. In the Closed event of the child
forms
I even tried to force a Dispose, but that don't seem to get rid of the
reference. ANy ideas.
THanks.
Michael