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

后端 未结 4 1233
清酒与你
清酒与你 2021-02-19 05:17

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 for

相关标签:
4条回答
  • 2021-02-19 05:24

    Simply change Show to ShowDialog; this also let's you get a return value to indicate whether the form considered itself exiting with a specific status (ok, cancel, etc).

    0 讨论(0)
  • 2021-02-19 05:31

    You want a modal dialog and I think you need NewCatForm.ShowDialog();

    0 讨论(0)
  • 2021-02-19 05:35

    You don't need to invoke when you are in the UI thread. And you are in the UI thread in a button-click eventhandler.

    private void btn_AddCat_Click(object sender, EventArgs e)
    {
        form_NewCat NewCatForm = new form_NewCat();
        var dialogResult = NewCatForm.ShowDialog();
        MessageBox.Show("Oops!");            
    }
    

    You can check the dialogResult for OK, Cancel, Yes, No, etc if your form_NewCat sets this.DialogResult to any value before closing. This is the usual way to signal how the user exited the form/dialog.

    0 讨论(0)
  • 2021-02-19 05:38

    Change the line

    NewCatForm.Show();
    

    to

    NewCatForm.ShowDialog();
    
    0 讨论(0)
提交回复
热议问题