[RESOLVED] How to recognize form [X] close?
I've just found this article on codeproject
http://www.codeproject.com/KB/dialog/CustomDialogs.aspx
and it's quite clear to me. However instead of using ShowDialog I'd like to use a simple Show because it should be a modeless form. I can set the DialogResult to OK or Cancel when I clicked a button and read it in a FormClosed event but how can I set it to Cancel when I clicked on the form's [X] symbol? I just can't figure it out :( I cannot change the DialogResult in FormClose or FormClosing event because it overwrites this what I've set on button's click.
Re: How to recognize form [X] close?
Then don't use DialogResult value if you can't figure out how to handle it. Declare a public variable in the form to save DialogResult value, after the form is closed, check the public variable.
Like: when OK button is clicked, set the public variable to DialogResult.OK; when Cancel button is clicked or [X] is clicked, set it to DIalogResult.Cancel.
Hope it helps.
Re: How to recognize form [X] close?
oh man, it's always the same, evertime when I ask a question I find the answer few minutes later. Before I asked it here I was looking everywhere with no success *lol* (this must be one of this creazy muphy's laws)
jasonli: that was the problem, I couldn't distinguish when a form was closed by a button and consequently with the Close() function and when with the [X] symbol, now I know how to do it
here's the cool solution: http://bytes.com/groups/net-c/278710-form-x-button