简体   繁体   中英

Form is closing instead of performing function when i press close button

In my project I am using two forms dialogForm and mainForm .

In mainForm I am calling the instance of the dialogForm something like this:

mainForm_Closing Event

private void mainForm_FormClosing(object sender, FormClosingEventArgs e)
{
    dialogForm dg = new dialogForm();
    dg.Show();
}

But in the above code, the mainForm is closing when I press close button and showing the dialogForm instead of even showing the mainForm .

I know I am doing something wrong here.

PS: I edited my question very much. If someone were working with my code then here it is .

You are using dg.Show() instead of dg.ShowDialog() . ShowDialog() will wait for the child dialog box to close before continuing to execute the instructions in the parent dialog box.

Return a value from the dialogForm and check if it is yes or no, and depending on that close the parent box.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM