出现问题的代码
private void mainForm_FormClosing(object sender, FormClosingEventArgs e)
{
//if (mainMenu != null)
{
_isSave.ShowDialog();
if (_isSave.ShowDialog() == DialogResult.Cancel)
{
e.Cancel = true;
}
else if (_isSave.ShowDialog() == DialogResult.No)
{
e.Cancel=false;
}
else if (_isSave.ShowDialog() == DialogResult.Yes)
{
e.Cancel = true;
}
}
}
每一个_isSave.ShowDialog()都会打开一次弹窗,所以为了解决这个问题,应只打开一次
private void mainForm_FormClosing(object sender, FormClosingEventArgs e)
{
//if (mainMenu != null)
{
//_isSave.ShowDialog();
DialogResult isSaveDia = _isSave.ShowDialog();
if (isSaveDia == DialogResult.Cancel)
{
e.Cancel = true;
}
else if (isSaveDia == DialogResult.No)
{
e.Cancel=false;
}
else if (isSaveDia == DialogResult.Yes)
{
e.Cancel = true;
}
}
}