473,385 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

mdi form not closing

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) ?

Nov 21 '05 #1
4 1189
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.

--
--Eric Cathell, MCSA
"Sam" <sa**************@voila.fr> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
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) ?

Nov 21 '05 #2
Sam
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?

Nov 21 '05 #3
Works for my needs...I dont know if I understand your needs enough to say
so...
--
--Eric Cathell, MCSA
"Sam" <sa**************@voila.fr> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
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?

Nov 21 '05 #4
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

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: RAJ | last post by:
hi plz tell me how to know "how window is going to close"... i have to right code for X button of forms... plz telll me thanks bye
1
by: Chris Bruce | last post by:
In my application I need a way to distiguish between the following events: 1. When a user closes an MDI child window. 2. When the user closes the MDI parent window which subsequently closes the...
6
by: Gary Miller | last post by:
Does anyone know how to detect a modeless form on closing by the form that invoked the modeless form? form.Show();
1
by: **Developer** | last post by:
When I get a closing event in a MID Child form I don't know if the child form is closing or the main form is closing. Is there a way to tell? Thank
11
by: Zytan | last post by:
I have created a new form from the main form. When I close the main form with the 'x' close button, its Form.FormClosed event is run, but not the dialog's. Is this normal? It is ok /...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.