views:

179

answers:

2

Dear all; i want to set a property that when the user clicks on X button in the title bar it check for some condition if all conditions are true then exit if no then do nothing and return to the form ..

but i noticed that FormClosing property exit the application howevere are my conditions ... so how to do my scenario ?!?

i'm using visual studio 2005 - C#

+5  A: 

In the FormClosing event, set e.Cancel to true before returning.

lc
+5  A: 

If you have already created the handler for the FormClosing event, just set the FormClosingEventArgs.Cancel property to True to cancel the closure of the form.

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
  if(myConditionsAreMet == false)
    e.Cancel = true;
}
Cerebrus