如何删除 DialogResult 对象?我将其用作清除表单的确认(删除所有控件并重新初始化控件)。问题是,当我点击“是”时,它会重新创建第二个 DialogResult,然后是第三个,然后是第四个,等等。
所以当用户点击是时,我想删除这个 DialogResult。有办法吗?
代码在这里:
private void GUI_DCP_FormClosing(object sender, FormClosingEventArgs e)
{
var confirmation_text = "If you click 'Yes', all information will be discarded and form reset. If you want to save the input click 'No' and then 'Save'";
DialogResult dialogResult = MessageBox.Show(confirmation_text, "WARNING", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
this.Hide();
e.Cancel = true; // this cancels the close event.
this.Controls.Clear();
this.InitializeComponent();
this.Height = 278;
this.Width = 341;
}
else
{
e.Cancel = true;
}
}