MDI gets FormClosing but non-Child forms also open do not.

A

Academic

I have a MDI form, sometimes child forms and sometimes forms that are
neither


If I close the app the child forms closing and closed event happens followed
by the Mdi form receiving the events..

But the regular forms that are also open do not receive that event. This is
true whether there are child forms open or not.

The MDI form is always open and always gets the events.

FormClosing works the same.


It appears to be true that if there is a MDI form other non-child forms do
not receive the events.

Is that correct???




Thanks
 
A

Academic

I generated a simple solution that has only a MDI form and a non-MDI
non-MdiChild form.

I open the regular form in the Load event of the Mdi form. The Mdi form is
the startup.

Both FormClosing events contain a console writeline statement.

When I click the X to exit the app I see only the output from the Mdi
FormClosing event.

None from the regular form.

It's really so simple that it might be easier to generate the solution then
to download it.
But is the someplace I can upload it so some of you experts might comment -
I'd hate to attach it.

I suppose this behavior could be by design but that seems unlikely.

Not getting the close and closing events when they are relied on is very
significant.
 
R

RobinS

Why would the non-MDI-child form be closed when you
close the MDI form? It's not a child of the MDI form,
and as far as it knows, it is not related in any way
to the MDI form. Closing the MDI form closes the
children (but not until after the MDI form is closed)
because they are related.

If you want to close the non-MDI-child form,
you will have to put something in the FormClosed
or FormClosing event of the MDI form that closes
it specifically.

And if you want the MDI form to close when the "normal"
form is closed, vice versa applies.

Robin S.
----------------------------------
 
G

Garry

Academic Hi,

I assume that there is a Forms collection for the application.

If you close the MDI, then, if your intention is truly to end the whole
application, loop, For Each, thru the Forms collection and close each one
individually except the MDI parent.

That should solve your problem although I haven't tried it in VB.NET.

On a philosophical level, you might reconsider why you have to have non-MDI
child forms floating around. That is - unless they are modal forms.

Garry
 
C

Cor Ligthert [MVP]

Academic,

There are about 12 methods to start a form, it depends from those methods
how you have to close a form.

Probably as you show how you start them, it will be easier to reply on your
question.

Cor
 
A

Academic

But if the application is closing the system will close all forms so I'd
expect the events to be called.
 
A

Academic

Really 12 ways. Maybe you're onto something.


In the real program, in the MdiContainer I do
If gFormCapture Is Nothing Then gFormCapture = New FormCaptureTool

gFormCapture.Show()

gFormCapture.BringToFront()



In the simple test program, in the MdiContainer I do

Imports System.Windows.Forms

Public Class MDIParent1

Private Sub MDIParent1_FormClosing(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

Console.WriteLine("Closing MDI")

End Sub

Private Sub MDIParent1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

Dim z As New Form1

z.Show()

End Sub

End Class

In the non-Mdi non-Child I do

Public Class Form1

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

Console.WriteLine("Closing Form1")

End Sub

End Class


THANKS
 
A

Academic

Maybe I didn't explain good enough.

It is for form that is not a MdiChild that the events are missing.
The MdiChildren and the MdiContainer all receive the events.
The standard folder does not.

If you have two standard forms they receive the events.
If you change one to a MdiContainer the standard form (that is, the one that
is not the MdiContianer) no longer receives the events.
If you like to know about the non-run-of-the-mill situations try the example
below. I think you'll be surprised.
Simply make a solution with two forms and make one a MdiContainer (do NOT
make the other a MdiChild)
Make the MdiContainer the startup form.
Run.
Then exit the app by clicking the stop on the MdiContainer.
And watch the standard form closing event.

Thanks
 
R

RobinS

You are going to have to close your forms yourself.
I don't understand what forms the user has open
and what is going on in your application. Just
because you close onevform, it does not necessarily
close all the forms, except in the case of
MDI parents/children.

If you want all forms to close when the MDI parent
is closed, you are going to have to code it that way.

I use a main form on my apps. From there, the user
can go to other forms. If he hits <Exit> on any
form to exit the application, I put a close for
the main form in my Form_Closed event. Then in
the Form_Closing event of my main form, I loop
through the open forms and close them, and then
let my main form close.

Robin S.
 
A

Academic

O.K. I've got it but I don't know why it's required. When I exit the app all
the forms are - I don't know what to call it if not "closed" - I guess
"exited" might be a better word if the events are not raised.

Since all the forms go away when the app is exited I guess I was assuming
they were closed.


Thanks for the info
 
R

RobinS

It's required because when you exit the app, the
forms are only closed if you close them. If you
check the Task Manager, you might find that
your app is still running. If you're running it
in the IDE, you probably have to click on the
stop button to get it to stop running.

Good luck.
Robin
 
A

Academic

thanks for the insight

RobinS said:
It's required because when you exit the app, the
forms are only closed if you close them. If you
check the Task Manager, you might find that
your app is still running. If you're running it
in the IDE, you probably have to click on the
stop button to get it to stop running.

Good luck.
Robin
 

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