Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Updated 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.
[no name] 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

It works fine for me:
C#
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.
 
Share this answer
 
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


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900