Solved

action upon closing form

Posted on 2006-11-27
5
317 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
Comment Utility
how about FormClosed property for the form?
0
 
LVL 35

Accepted Solution

by:
Raynard7 earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I found that I had to add to initialize components:

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now