473,406 Members | 2,894 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,406 software developers and data experts.

Shutting down GUI apps


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.

Jan 18 '07 #1
6 964
You already have it.

It is called the FormClosing event of the Form class.
"_AnonCoward" <ab*@xyz.comwrote in message
news:45**********************@roadrunner.com...
>
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.

Jan 18 '07 #2

"Stephany Young" <noone@localhostwrote in message
news:uo*************@TK2MSFTNGP04.phx.gbl...
:
: 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
: "_AnonCoward" <ab*@xyz.comwrote in message
: news:45**********************@roadrunner.com...
: >
: 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.
Jan 18 '07 #3
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.
"_AnonCoward" <ab*@xyz.comwrote in message
news:45**********************@roadrunner.com...
>
"Stephany Young" <noone@localhostwrote in message
news:uo*************@TK2MSFTNGP04.phx.gbl...
:
: 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
: "_AnonCoward" <ab*@xyz.comwrote in message
: news:45**********************@roadrunner.com...
: >
: 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.


Jan 18 '07 #4
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?

Regards,
Phill W.
Jan 19 '07 #5
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.
"Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-kwrote in message
news:eo**********@south.jnrs.ja.net...
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?

Regards,
Phill W.

Jan 19 '07 #6

"Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-kwrote in message
news:eo**********@south.jnrs.ja.net...
:
: 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
--
--
----------------------------------------------------------
* ^~^ ^~^ *
* _ {~ ~} {~ ~} _ *
* /_``>*< >*<''_\ *
* (\--_)++) (++(_--/) *
----------------------------------------------------------
There are no advanced students in Aikido - there are only
competent beginners. There are no advanced techniques -
only the correct application of basic principles.


Jan 20 '07 #7

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

Similar topics

10
by: Jesper | last post by:
Does anyone know some c++ code for shutting down windows? I want to write a program using borland c++ builder to shut down windows. --
1
by: mikelostcause | last post by:
I'm working on shutting down an app that runs in the system tray, I have no problems shutting down, but I have problems saving data first. if the base.WndProc(ref m) is placed at the top, it...
2
by: Mike Stephens | last post by:
I have an application to minimizes when X is clicked. If the user wants to close the application they click the Exit Application button.This works fine and does exactly what I need. I have since...
4
by: Markus Stoeger | last post by:
Hi, I have a problem with Application.Run() when Windows is shutting down. Please have a look at the copy&paste example program below. The application has no forms. It has only got a notify...
7
by: Mark | last post by:
It is possible from a .NET application to prevent Windows from shutting down? I understand that a .NET application can "know" that windows is initiating the process of to shutting down - but...
3
by: leocwh | last post by:
Dear all, I would like to know how to run the execuatable before windows shutting down. Here is my simple code: Private Sub Command1_Click() Shell "C:\abc.bat", vbNormalFocus End Sub ...
2
by: Jack | last post by:
Sorry for the double post (also in the IIS group). We've got an ASP.Net 2.0 app running on IIS6. We kept losing sessions, and enabled health monitoring to see what was happening. This morning...
4
by: Larry Bud | last post by:
Not sure where else to post this.... One of our developers quit and I'm taking over stuff from him. He had a COM app that would lock files on occasion (yeah, thanks for leaving that in...
2
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I am monitoring web apps with the windows event log and noticed several (Hosting environment is shutting down) statements. The server appears to still be running, just wondering any ideas on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.