mdi form not closing

  • Thread starter Thread starter Sam
  • Start date Start date
S

Sam

Hi,
I have a mdi application in which it is only possible to open one form
at a time. To achieve this I have:

Public Class clsForms
Public Shared frm As Form
End Class

and then when I open a new form:

If Not form Is Nothing Then

If Not clsForms.frm Is Nothing Then
clsForms.frm.Close()
clsForms.frm = Nothing
End If

clsForms.frm = form
clsForms.frm.MdiParent = Me
clsForms.frm.Show()
clsForms.frm.Focus()
End If

It works fine except when I open a pop-up form from the toolbar of the
main form. When i do that, then if I try to open another form after i
closed the pop-up, clsForms.frm is not closed and i end up with having
multiple forms opened.

What is the problem with these pop-up (modal form) ?
 
First I am curious why you would only want one form open at a time in an
mdi...

If you only want a single instance of the forms to open you are going about
it with a great amount of complexity. All you need is to add this to your
working form:

Private Sub New
End Sub

Private shared m_FrmSomeForm as frmSomeForm
private shared function GetInstance as frmSomeForm
if m_FrmSomeForm is nothing then
m_frmSomeForm=new frmSomeform
end if
return m_frmSomeform
end function

in your MDI:

dim frm as frmSomeForm

frm=frm.getinstance

That way you only have one instance of each form available. Then in the MDI
in your closing event:
e.cancel=false

then when you close your MDI all your child forms will close.
 
Hi,
Thanks for the reply.
That way you only have one instance of each form available
It's not exactely what I want. I want only one form opened at a time,
regardless its type. So if frmFormA is opened and I try to open
frmFormB then frmFormA should be closed.

Is your method going to work?
 
Works for my needs...I dont know if I understand your needs enough to say
so...
 
Dim f as Form
For each f In Me.MDIChildren
f.Close()
Next 'f
'Now comes the code to open your new form

Hope this helps,
zdrakec
 

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

Back
Top