On Mar 9, 8:35 am, "Smokey Grindel" <nos...@nospam.comwrote:
What is the best way to do this? I want to have a child form in an MDI
window that can only ever have one instance of open... if one is already
opened I want to use that form and not make another... any suggestions? I
have one idea but looking to see what alternatives are out there. thanks!
This is screaming singleton to me.
Here's the basic pattern:
Public Class MyForm
Private Sub New()
InitializeComponent()
' This prevents the class from being instantiated directly.
End Sub
Private Shared _Instance As MyForm
Public Shared ReadOnly Property Instance() As MyForm
Get
' Instantiate the class if needed, otherwise return the
current class
If (_Instance Is Nothing) Then _Instance = New MyForm()
Return _Instance
End Get
End Property
End Class
Then in the MDI parent you can do this to add the child form:
MyForm.Instance.MdiParent = Me
MyForm.Instance.Show()
For more (and better implementations) see Jon Skeet's article at
http://www.yoda.arachsys.com/csharp/singleton.html
Beware it's in C#
Thanks,
Seth Rowe