Click here to Skip to main content
12,821,084 members (38,187 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

this.ParentForm.FormClosing += new FormClosingEventHandler(ParentForm_FormClosing);

void ParentForm_FormClosing(object sender, FormClosingEventArgs e)

it's not working

Thanks in advance
Posted 28-Aug-12 4:04am
Updated 28-Aug-12 4:09am
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
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.
ridoy 28-Aug-12 10:03am

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
Web02 | 2.8.170308.1 | Last Updated 28 Aug 2012
Copyright © CodeProject, 1999-2017
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