Solved

action upon closing form

Posted on 2006-11-27
5
321 Views
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?
0
Comment
Question by:g_johnson
5 Comments
 
LVL 16

Expert Comment

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

Accepted Solution

by:
Raynard7 earned 500 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.

http://msdn2.microsoft.com/en-us/library/system.windows.forms.form.closed.aspx

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

http://msdn2.microsoft.com/en-us/library/system.windows.forms.form.formclosed.aspx
0
 
LVL 15

Expert Comment

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

Author Comment

by:g_johnson
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)
{
     MessageBox.Show("Here");
     <----------------------------------------this is where I would like to update a database
}

Any idea what I'm doing wrong?
0
 
LVL 4

Author Comment

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

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that undeā€¦
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled

808 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