Solved

Saving Dirty Forms on Windows App Close (C# .Net 2.0)

Posted on 2007-03-23
4
1,607 Views
Last Modified: 2007-11-27
Experts,

I need some general advice on Windows form application development.  We're writting a module for Microsoft's CAB framework.  Our main content for this module is a DockPanel, ultimately containing multiple forms displayed as tabs.

What I'd like to be able to do is check each tab when the application is quit to see if the form is dirty, and if so, prompt the user to save his/her changes.  I've done this sucessfully for each close of the tab, but I'm not sure what the cleanest solution is to implement this on the application closing.

I can add an event listener to the onClosing event of the Shell Application, but that seems a bit dirty.  I don't know that I'm properly using the validation provided by windows, it seems like all forms should validate when they are unloading.

Any advice?

Thanks in advance,
dK
0
Comment
Question by:dkDeveloper
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 13

Accepted Solution

by:
Webstorm earned 500 total points
ID: 18780022
Hi

You can use the form FormClosing event and check the FormClosingEventArgs CloseReason property is CloseReason.UserClosing . In this event handler you check if you need to save, if so, ask the user. If you have to cancel the exit, just set the Cancel property of the FormClosingEventArgs parameter.
0
 
LVL 5

Author Comment

by:dkDeveloper
ID: 18780435
I gave that a shot and for some reason the FormClosing event isn't firing when the application is closing.  This could have something to do with the fact that it's a Module in the CAB, or it might be due to the fact that the form is a DockContent form inside of a DockPanel.

At any rate - no luck with that.

Any other thoughts or suggestions?

Thanks,
dK
0
 
LVL 1

Expert Comment

by:swiatlo
ID: 18935199
What about in destructor of a from. Can you have those form as your own class derived from current form class?
0
 
LVL 5

Author Comment

by:dkDeveloper
ID: 18935253
I ended up creating an interface that basically contains a method to determine if the form is dirty, a method to prompt saving, and a method to actually save the form.  Then when the main shell.application form is closing I loop through all open tabs and utilize that interface to force those windows to potentially save themselves.

This really shouldn't have been this difficult and I think I just ran into so many problems with it due to the fact that we were using both the CAB and other third party controls.  At any rate, thanks to everyone for trying to help.  I'm going to go ahead and (partially) accept WebStorms answer since that is generally what you would do.

Thanks again guys!
dK
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question