我有MDI form
一些儿童表格需要在关闭之前显示一个消息框,而其他表格可以在不询问的情况下关闭。由于application.Exit()
从close event
子窗体调用时出现问题,我处理close event
父窗体并检查它的触发位置。如果它是在需要消息框的表单中触发的,我会调用它,否则只需关闭应用程序。所有这些都在这段代码中实现:
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
SEdit se = this.ActiveMdiChild as SEdit;
SoEdit soleEdit = this.ActiveControl as SoEdit;
UppEdit ue = this.ActiveControl as UpEdit;
MEdit mat = this.ActiveControl as MEdit;
LEdit lse = this.ActiveControl as LEdit;
CEdit cle = this.ActiveControl as CEdit;
if (se != null || soleEdit != null || ue != null || mat != null || lse != null || cle != null)
{
if (MessageBox.Show("Do you want to save before exit?", "Closing",
MessageBoxButtons.YesNo,
MessageBoxIcon.Information) == DialogResult.Yes)
{
MessageBox.Show("To Do saved.", "Status",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}
}
我还在学习,但我知道这么长的 if 语句是错误代码的标志,但我不知道如何改进它。处理这种情况的正确方法是什么?