请帮我解决这个表单关闭后点击按钮执行,因为我只依靠windows关闭按钮(右上角),我没有使用额外的按钮来关闭表格。 但是,这个程序仍然在工作,但不会在保存.ini文件后立即自动关闭表单。表格关闭之后:button.performclick
我希望表单在button1.performclick()后关闭...但我不知道该怎么办..
我有以下代码:
int beFore, afTer;
private void Form3_Load(object sender, EventArgs e)
{
beFore = this.checkedListBox1.CheckedIndices.Count +
this.checkedListBox2.CheckedIndices.Count +
this.checkedListBox3.CheckedIndices.Count +
this.checkedListBox4.CheckedIndices.Count;
}
//private Form4 subForm4 = new Form4();
private void Form3_FormClosing(object sender, FormClosingEventArgs e)
{
afTer = this.checkedListBox1.CheckedIndices.Count +
this.checkedListBox2.CheckedIndices.Count +
this.checkedListBox3.CheckedIndices.Count +
this.checkedListBox4.CheckedIndices.Count;
while (beFore != afTer)
{
if (MessageBox.Show("Changes have been made..\r\nSave to configuration file (.ini) ?", "Warning",
MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
{
this.button1.PerformClick(); //need to close this form after button.performclick..
this.UpdateForm1();
break;
}
else
{
this.UpdateForm1();
break;
}
}
beFore = afTer;
}
private void UpdateForm1()
{
Form4 subForm4 = new Form4();
subForm4.Show();
subForm4.Update();
try
{
int checkagain1 = this.checkedListBox1.CheckedIndices.Count; this.checkedListBox1.SetItemChecked(2, true);
int checkagain2 = this.checkedListBox2.CheckedIndices.Count; this.checkedListBox2.SetItemChecked(2, true);
int checkagain3 = this.checkedListBox3.CheckedIndices.Count; this.checkedListBox3.SetItemChecked(2, true);
int checkagain4 = this.checkedListBox4.CheckedIndices.Count; this.checkedListBox4.SetItemChecked(2, true);
Form1 myParentForm = (Form1)this.Owner;
if (myParentForm.comboBox1.Text.Length != 0)
{
//myParentForm.Enabled = false;
myParentForm.method1();
myParentForm.method2();
myParentForm.method3();
myParentForm.method4();
//myParentForm.Enabled = true;
subForm4.Close();
}
}
catch (Exception)
{
subForm4.Close();
return;
throw;
}
}
如果你想人们可以帮助你,请花更多的精力来格式化你的代码。我可以理解,英语很可能是你的第二语言,但你很难理解,问题不清楚。 – 2013-03-14 14:24:16
什么是错误? – 2013-03-14 14:24:20
我很抱歉的朋友,但目前还不清楚你想要做什么。我们看到了代码,并且隐约地理解了您对表单关闭时点击某个按钮所说的内容,但是您并没有清楚地解释***到底是什么。*** – 2013-03-14 14:25:27