Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make execution pause until new form is closed?

Tags:

c#

winforms

I am making a Win Forms application to learn more since I don't have much experience with it. In my program, in the main form, I have a button. Clicking it launches another form. The code is as follows:

 private void btn_AddCat_Click(object sender, EventArgs e)
        {
            this.Invoke(new MethodInvoker(() =>
            {
                form_NewCat NewCatForm = new form_NewCat();
                NewCatForm.Show();
            }));

            MessageBox.Show("Oops!");            
        }

The problem is, when the new form is launched, I want execution of the code behind the main form to pause at that point until the new form is closed. As an example, in the above code, I do not want 'Oops!' to get printed until the new form is closed. How can I achieve that?

like image 309
xbonez Avatar asked Dec 05 '10 16:12

xbonez


1 Answers

Change the line

NewCatForm.Show();

to

NewCatForm.ShowDialog();
like image 56
Venemo Avatar answered Sep 30 '22 08:09

Venemo