Just the form closing or application closing?

  • Thread starter Thread starter **Developer**
  • Start date Start date
D

**Developer**

I've been looking but can't find out how in a form Closing event to know if
the closing is because the form's "X" had been clicked or the main form's
"X" was clicked.

That is, I need to know if just the form is closing or the application is
closing.

Do you know how to tell?


Thanks
 
**Developer** said:
I've been looking but can't find out how in a form Closing event to know if
the closing is because the form's "X" had been clicked or the main form's
"X" was clicked.

That is, I need to know if just the form is closing or the application is
closing.

Do you know how to tell?
I had this same puzzle - I just set a global flag when the program is
closing, so the form can check it.

Tom
 
I had this same puzzle - I just set a global flag when the program is
closing, so the form can check it.

I do the same thing. In simple apps, it doesn't matter much. But with
several forms and/or several threads and/or several open resources, you are
kind of fixed. An-app wide shutting down flag seems like the simplest
solution.
 
tomb and AMercer

Thanks

AMercer said:
I do the same thing. In simple apps, it doesn't matter much. But with
several forms and/or several threads and/or several open resources, you
are
kind of fixed. An-app wide shutting down flag seems like the simplest
solution.
 
How do you set the flag.
I believe the other form's Closing event occurs before the main form's
closing event.
 
How do you set the flag.

I set it in the main form's closing event handler.
I believe the other form's Closing event occurs before the main form's
closing event.

In my apps, if I close the main window, its closing event fires first,
shutdown is indicated, and then secondary windows close. If I close a
secondary window, its closing event fires, but nothing else happens.
 
I'm working on a MDI app.

It has forms that are non-MDI child and some that are.

The non-MDI child work as you say but the child always closes first.

You said "shutdown is indicated."

How do you check that?

Maybe I can use that somehow.

Thanks
 
I'm working on a MDI app.

No experience with mdi. Perhaps events fire differently?
You said "shutdown is indicated."
How do you check that?

In a public module, declare the shutdown flag, something like:

Public Module SomeNameYourChoice
Public AppIsShuttingDown As Boolean = False
End Module

In the main form's closing event:

AppIsShuttingDown = True

In other places that need to know if the app is shutting down or not:

If AppIsShuttingDown Then
' whatever you want if shutting down
Else
' whatever you want if not shutting down
Endif
 
Thanks
I knew how to do that.
I was hoping one of the Closing event arguments had a clue or maybe the
Application class did.
I had looked but couldn't find anything.

Thanks again
 

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