MDI Child Question

  • Thread starter Thread starter Steve Peterson
  • Start date Start date
S

Steve Peterson

Hello

Just a quick question.. I have a MDI app that allows the user to open
several child forms.. Nothing special. However, what I would like to know is
how to prevent a user for opening the same form twice. I don't want to use
the myfrm.ShowDialog method, but rather be able to check & see if the form
is already open, and if so, simply set it's focus..

Any help would be appreciated

Thx
Steve
 
You could use a shared default instance for your forms - this way, only ever
one instance of the form exists.

e.g.

------------------------

' Place this in your form class - Rename "MyForm" to the class name of your
form
Private Shared mDefaultInstance as MyForm
Public Shared Readonly Property DefaultInstance() as MyForm
Get

' Check if form has been closed or hasn't been created yet
if mDefaultInstance is nothing orelse mDefaultInstance.IsDisposed
then
mDefaultInstance = new MyForm
end if

return mDefaultInstance

End Get
End Property


' When accessing the form from other forms use:
MyForm.DefaultInstance.Show()
 
Thnks HTH - It did the trick!

However, I did need to slightly deviate from your example to get it to work
correctly, but I'm sure it's just another way of killing the same bird, but
with a different stone (just an expression - no offense to all you nature
lovers)... :

In my MDI parent form I put this:

'Make sure we don't open more than one form at a time
Dim frm As MyForm = frm.DefaultInstance
'Set MDI parent property
frm.MdiParent = Me
'Show form
frm.Show()
'If minimized restore to normal
If frm.WindowState = FormWindowState.Minimized Then
frm.WindowState = FormWindowState.Normal
End If
'Set focus
frm.Focus()


Thx again
Steve
 
Yeah, I forgot about the activation of the form if it is behind another form
or is minimized.

By the way, "HTH" stands for "Hope This Helps", not my name ;)

Best Regards,

Trev.
 
OOOPS! Sorry Trev!


Codemonkey said:
Yeah, I forgot about the activation of the form if it is behind another form
or is minimized.

By the way, "HTH" stands for "Hope This Helps", not my name ;)

Best Regards,

Trev.
 
Back
Top