Home > Net >  FormClosing event in C#
FormClosing event in C#

Time:05-04

I'm doing a C# app with multiple Forms, like Help, Feedback, Register, Login, etc. I try to override the FormClosing, like when the user presses X in the upper right to close the form, to return to the previous form that was opened.

I tried something like this

private void QuestionForm_FormClosing(object sender, FormClosingEventArgs e)
{
            this.Hide();
            HelpForm help = new HelpForm();
            help.FormClosed  = (s, args) => this.Close();
            help.Show();
}

but when I press X, only the Question Form closes, and the Help Form that let's say was the previous one, shows up like 0.1s and the whole app closes.

CodePudding user response:

Acoording to the comments, We can find the solution to this problem is to use ShowDialog.

You can use this method to display a modal dialog box in your application.

When this method is called, the code following it is not executed until after the dialog box is closed.

  • Related