[英]Form is closing instead of performing function when i press close button
In my project I am using two forms dialogForm
and mainForm
. 在我的项目中,我使用两种形式dialogForm
和mainForm
。
In mainForm
I am calling the instance of the dialogForm
something like this: 在mainForm
我打电话的实例dialogForm
是这样的:
mainForm_Closing Event mainForm_Closing事件
private void mainForm_FormClosing(object sender, FormClosingEventArgs e)
{
dialogForm dg = new dialogForm();
dg.Show();
}
But in the above code, the mainForm
is closing when I press close button and showing the dialogForm
instead of even showing the mainForm
. 但在上面的代码中, mainForm
是当我按下关闭按钮关闭和表示dialogForm
甚至示出的代替mainForm
。
I know I am doing something wrong here. 我知道我在这里做错了。
PS: I edited my question very much. PS:我经常编辑问题。 If someone were working with my code then here it is . 如果有人在使用我的代码,那就在这里 。
You are using dg.Show()
instead of dg.ShowDialog()
. 您正在使用dg.Show()
而不是dg.ShowDialog()
。 ShowDialog()
will wait for the child dialog box to close before continuing to execute the instructions in the parent dialog box. ShowDialog()
将等待子对话框关闭,然后继续执行父对话框中的指令。
Return a value from the dialogForm and check if it is yes or no, and depending on that close the parent box. 从dialogForm返回一个值,并检查它是是还是否,并根据该值关闭父框。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.