action upon closing form

Posted on 2006-11-27
Medium Priority
Last Modified: 2010-04-16
I have frmMain, which opens frmEvent from within a timer (f.Show not ShowDialog).

When I close the instance of frmEvent by clicking on the X in the ControlBox, I want to update a database.
I can't find any kind of close event in frmEvents memebers.

How do I do this?
Question by:g_johnson
LVL 16

Expert Comment

ID: 18023261
how about FormClosed property for the form?
LVL 35

Accepted Solution

Raynard7 earned 1500 total points
ID: 18023282
Hi you should be able to use the Form.Closed event for the form.  If you are unable to add it through the GUI you can use the delegation given below.


or with 2005 (.NET 2.0) you would be better using the formclosed event for the form

LVL 15

Expert Comment

ID: 18026648
If you are looking to close a form could you not just use this.Close(); upon an event?

Author Comment

ID: 18028868
I have tried the following and can't spot what I am doing wrong.  I also tried the "closing" rather than "closed" event.

After build, "Closed" is underlined saying "never used"
public event EventHandler Closed;

This code never executes:
private void frmEvent_Closed(object sender, System.EventArgs e)
     <----------------------------------------this is where I would like to update a database

Any idea what I'm doing wrong?

Author Comment

ID: 18029978
I found that I had to add to initialize components:

//      form closing
this.Closing += new System.ComponentModel.CancelEventHandler(this.frmEvent_Closing);  

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
In this video I will demonstrate how to set up Nine, which I now consider the best alternative email app to Touchdown.
Watch the video to know how one can repair corrupt Exchange OST file effortlessly and convert OST emails to MS Outlook PST file format by using Kernel for OST to PST converter tool. It can convert OST to MSG, MBOX, EML to access them. It can migrate…

586 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