I have a form (let's call it parent form), from which another "always on top but not modal" form can be loaded (Like a dialog but not a dialog - user can leave the new "child form" where it is and continue to work on the parent form).
The first time the user opens that child form some data is loaded and displayed. Should they close the form, I actually intercept the close and simply hide the form - so that next time they open it, we don't have to reload the data (it is not data that changes very much if at all).
if (e.CloseReason == CloseReason.UserClosing)
{
e.Cancel = true;
this.Hide();
}
Later, when the parent form is closed, I want to force the child form to close properly - running some code in it's base form to store its location and size for next time.
Currently I call childForm.Dispose() from the parent form which cleans thing up nicely, but doesn't give me much control.
However, if I call the childForm.Close() method, the e.CloseReason is still "CloseReason.UserClosing".
Is there a way to distinguish between the user closing the form and my code (in the parent form) closing it?
Just add a special "
ReallyClose()
" method that does your cleanup and is called when you really want to close the form.