Search code examples
c#winformseventsmdi

Need an event to fire when a Form in an MDI container closes?


I have a Multi Document Interface control with some Forms nested inside of it. I need an event to fire when one of those forms are closed. How may I bind such an event?

If it matters, the code I need to run accesses a global class called data, which has a public static property called Windows, which is accessed like so:

data.Windows -= 1;

Solution

  • It is indeed as L.B says: Create an override in the form class. It can be placed anywhere in the class

    protected override void OnClosing(CancelEventArgs e) data.Windows = -1; //assuming this variable still exists at that time }