Single instance form (child) on MDI

S

Smokey Grindel

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!
 
S

Screaming Eagles 101

Try

Me.Cursor = Cursors.WaitCursor

If IsNothing(frmCust) Then

frmCust = New frmCustomers

frmCust.MdiParent = Me

frmCust.Show()

Else

frmCust.BringToFront()

End If

Finally

Me.Cursor = Cursors.Default

End Try
 
R

rowe_newsgroups

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
 
S

Smokey Grindel

thats actually the say I already had it :) good to know someone else was
thinking similar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top