private void closeBtn_Click(object sender, EventArgs e) { if (MsgBox == null) { MsgBox = new MyMsgBox(); bool wasVisible = _ct_save_current_state.Visible; foreach (Control c in op_container.Controls) { c.Visible = false; } op_container.Controls.Add(MsgBox); MsgBox.Left = (op_container.Width - MsgBox.Width) / 2; MsgBox.Top = (op_container.Height - MsgBox.Height) / 2; new Thread(new ThreadStart(() => { while (MsgBox.res == 0) { ; } if (MsgBox.res == 1) { Environment.Exit(0); } else { MsgBox.Dispose(); MsgBox = null; foreach (Control item in op_container.Controls) { if (item != _ct_save_current_state) { item.Visible = true; } else if (wasVisible) { _ct_save_current_state.Visible = true; } } } })) { IsBackground = true }.Start(); } }