Shutting down GUI apps

A

_AnonCoward

I have a windows GUI application (vb.net 2.0) and I need to manage how
it is closed. I want to have a single function that is called whenever
the user tries the close the app regardless of how:


* User selects File|Exit from the main menu
or clicks a [Close] button.


* the system is being shut down via the [X]
button, or the system menu from the task
bar (etc.)


My objective is to have this function perform the following tests:


[1] if there isn't a current document loaded
return True

[2] if the current document isn't "dirty",
return True

[3] prompt the user to save the document. If
that succeeds, return True. If the save
fails or the user cancels the action,
Return False


If the function returns True, the shut down will be allowed to
continue. If it returns false, the shut down will be aborted.


Any suggestions on the best approaches to take for this?


Ralf
 
A

_AnonCoward

:
: You already have it.
:
: It is called the FormClosing event of the Form class.

That's just seems too simple! But it works. I looked a little closer
at the FormClosingEventArgs parameter to the function and sure enough,
setting the cancel property to True aborted the shut down. How about
that...

That's what I needed. Thanx,

Ralf


: : >
: > I have a windows GUI application (vb.net 2.0) and I need to manage
: > how it is closed. I want to have a single function that is called
: > whenever the user tries the close the app regardless of how:
: >
: >
: > * User selects File|Exit from the main menu
: > or clicks a [Close] button.
: >
: >
: > * the system is being shut down via the [X]
: > button, or the system menu from the task
: > bar (etc.)
: >
: >
: > My objective is to have this function perform the following tests:
: >
: >
: > [1] if there isn't a current document loaded
: > return True
: >
: > [2] if the current document isn't "dirty",
: > return True
: >
: > [3] prompt the user to save the document. If
: > that succeeds, return True. If the save
: > fails or the user cancels the action,
: > Return False
: >
: >
: > If the function returns True, the shut down will be allowed to
: > continue. If it returns false, the shut down will be aborted.
: >
: >
: > Any suggestions on the best approaches to take for this?
: >
: >
: > Ralf
: > --
: > --
: > ----------------------------------------------------------
: > * ^~^ ^~^ *
: > * _ {~ ~} {~ ~} _ *
: > * /_``>*< >*<''_\ *
: > * (\--_)++) (++(_--/) *
: > ----------------------------------------------------------
: > There are no advanced students in Aikido - there are only
: > competent beginners. There are no advanced techniques -
: > only the correct application of basic principles.
 
S

Stephany Young

I'm glad you've got it sussed.

It's not 'too simple'. That's exactly what that event is designed for.

Note that the FormClosingEventArgs parameter also has a property that gives
the reason for the form closing. One of the reasons is that Windows is
hutting down. When that is the reason you may need to consider bypassing
your logic.
 
P

Phill W.

Stephany said:
I'm glad you've got it sussed.

It's not 'too simple'. That's exactly what that event is designed for.

Agreed.

Am I the only one that thinks it "sad" that people regard a
well-designed and well-functioning VB feature such as this as being "too
simple" in this Brave New World of .Net?

Regards,
Phill W.
 
S

Stephany Young

Not at all Phill. I'm sure there are, at least, a few of us.

While, I don't have a problem with people striving for an acedemically or
technically 'pure' way of doing something, per se, I do tend to give people
an earful when I do hear them trotting out the 'there must be a better way
because that way is too simple' line.
 
A

_AnonCoward

:
: Stephany Young wrote:
: >
: > I'm glad you've got it sussed.
: >
: > It's not 'too simple'. That's exactly what that event is designed
: > for.
:
: Agreed.
:
: Am I the only one that thinks it "sad" that people regard a
: well-designed and well-functioning VB feature such as this as being
: "too simple" in this Brave New World of .Net?

<sigh>

It was humor, and slightly self deprecating at that. I had found this
form method and had considered it but thought I might be overlooking
something because it seemed too, well, simple or perhaps just a little
too obvious. I don't like to make assumptions when I code and just
because a given function may seem at first blush to do what I need, it
isn't necessary so. I was looking for input from the larger community
on what approaches other's have taken and any advice on potential
problems I should be on the look out for.


Ralf
 

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