This is from my mainForm:
private void buttonAdd_Click(object sender, EventArgs e)
{
//New ContactForm
ContactForm contactForm = new ContactForm();
}
The ContactForm opens and then I fill in some data and I press the button called Add:
private void buttonAddContact_Click(object sender, EventArgs e)
{
bool isDataOk = false;
isDataOk = contact.AddAddress(textBoxFirstName.Text,
textBoxLastName.Text,
textBoxPhoneHome.Text,
textBoxPhoneCell.Text,
textBoxEmailPrivate.Text,
textBoxEmailBusiness.Text,
textBoxStreet.Text,
textBoxCity.Text,
textBoxZipcode.Text,
comboBoxCountries.Text);
}
And now my Form closes which seems to be logical. However I want that when isDataOk = false (i.e. the input data doesn't look 100%) it should now close.
I'm not sure where and how I should put this. Can anyone please assist me in this?
Best regards,
Tomas

VulpesPosted Nov 16, 2012, 4:57 AM
Tomas WesterlundPosted Nov 16, 2012, 6:06 AM
For other people:
* Choose the form in the designer
* FormClosing exists under "Events" just select it and double-click
Thanks!
Tomas WesterlundPosted Nov 16, 2012, 5:18 AM
I don't get it really. How and when will Form1_FormClosing be executed?
Best regards,
Tomas
VulpesPosted Nov 16, 2012, 5:11 AM
If your CheckDate method is closing the form programatically then, of course, you can refrain from doing so if the data is not OK.
Tomas WesterlundPosted Nov 16, 2012, 5:05 AM
When I click the buttonAddContact_Click all the checks are done my a method called CheckDate in contact.AddAddress.CheckData.
If anything looks bad an mbox popups with the problem. So if the data is _not_ ok I would like the user to able to continue with his form i.e. I don't want the ContactForm to be closed if there is any problem with the formatting.
Best regards,
Tomas