Click here to Skip to main content
15,921,174 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
(2)
Thanks, it works now by according to your great comments(answer).


(1)
Hi, I am writing a Windows Form application.
When clicking a button (button A) on Main form (form A), I create a New form (form B) from Main form (form A).

The question is:
How can form A know form B is closed, so that form A can automatically do some process?
Posted
Updated 8-Jun-10 18:02pm
v3

Have Form A subscribe to FormClosing event of FormB:

Example:

C#
public partial class FormA : Form
{
    FormB b;
    public FormA()
    {
        InitializeComponent();
        b = new FormB();
        b.FormClosed += new FormClosedEventHandler(b_FormClosed);
        b.Show();
    }
    void b_FormClosed(object sender, FormClosedEventArgs e)
    {
        MessageBox.Show("Form B Has now closed");
    }
}
 
Share this answer
 
v2
yes you can use the above method if it matches to your requirement , but if the form B is not created with in the form A you can use custom event to catch the B forms close method .
 
Share this answer
 
Comments
Henry Minute 8-Jun-10 9:35am    
The OP clearly stated that Form B WAS created in Form A. So why are you replying in this way?

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



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