Click here to Skip to main content
12,301,965 members (55,565 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# Windows
hi all

How to know usercontrol(form) is closing or not?

let me know

my code

//pageload
this.ParentForm.FormClosing += new FormClosingEventHandler(ParentForm_FormClosing);
 
void ParentForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            UpdateAll();
        }

it's not working

Thanks in advance
Posted 28-Aug-12 3:04am
U@0071K
Edited 28-Aug-12 3:09am
v3
Comments
Legor 28-Aug-12 9:08am
   
What do you mean by "Its not working" ? What isn't working.
Wes Aday 28-Aug-12 9:08am
   
"it's not working".. is not a helpful description of any kind of a problem. What is not working? How does it not perform to your satisfaction? Does the event handler not get called? Does the UpdateAll() method not execute? Did the city burn down when you ran this code?

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

It works fine for me:
void ParentForm_FormClosing(object sender, FormClosingEventArgs e)
    {
    Console.WriteLine("Form closing");
    }
 
private void UserControl1_Load(object sender, EventArgs e)
    {
    ParentForm.FormClosing += new FormClosingEventHandler(ParentForm_FormClosing);
    }
Check that you have hooked up the Load event handler for your control.
  Permalink  
Comments
ridoy 28-Aug-12 10:03am
   
good..+5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160530.1 | Last Updated 28 Aug 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100