How to stop a windows Forms application until a form is closed?

Asked

Viewed 67 times

0

I want when Form1 is opened, the whole program stops, and only comes back when it is closed. How can I do this?

Code that opens Form1:

if (x == DialogResult.Yes)
{
    Form1 f1 = new Form1();
    f1.Show();
}

1 answer

1


To "block" the application while waiting for the result of Form1, swap the .Show for .ShowDialog().

  • I tried to do that, it even worked, but it’s just that inside the Form1.cs, I have a function that assigns some values within a combobox, and when I open with the f1.ShowDialog() he doesn’t perform it.

  • this function is running at what time ? use the Form1 Load event

  • Yes, it’s in the load.

  • If you can, post the Form code

  • This is the entire code: https://gist.github.com/ceifa/36c0771bc0757ec954118493ffd56a07

  • and without Showdialog it works ?

  • Yes, if I put it to him to be the first form to boot, it works normally.

  • so you don’t just change Showdialog to Show, you change something else in the code... ?

  • No. I change nothing.

  • Put a point break in the code and check if the values of the Skins variables. x are not empty

  • No, they are not empty, as I said, if I put to be the first form to start, everything works perfectly.

Show 6 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.