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


VulpesRank #55 · 29.2K reputationPosted Nov 15, 2012, 11:57 PM EST
Tomas Westerlund38 reputationPosted Nov 16, 2012, 12:05 AM EST
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
VulpesRank #55 · 29.2K reputationPosted Nov 16, 2012, 12:11 AM EST
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 Westerlund38 reputationPosted Nov 16, 2012, 12:18 AM EST
I don't get it really. How and when will Form1_FormClosing be executed?
Best regards,
Tomas
Tomas Westerlund38 reputationPosted Nov 16, 2012, 1:06 AM EST
For other people:
* Choose the form in the designer
* FormClosing exists under "Events" just select it and double-click
Thanks!