Kindly help me to solve this form closing fire after button perform click, since I only depend on windows close button (top right corner), I do not use additional button to close the form. However this program is still working but not automatically close the form right after save the .ini file..
I want the form closed ...after button1.performclick(), but I don't know what to do..
I have following codes:
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;
}
}