Unfortunately,
the CloseReason enum doesn't distinguish between the user closing the
form and your code closing the form. A bit of oversight I'd say
but there is probably a Windows restriction that forces that. The
workaround is pretty straight-forward:
private bool mItsMeClosingIt;
...
public sub CloseForm() {
mItsMeClosingIt = true;
this.Close();
}
...
if (e.CloseReason == CloseReason.UserClosing) e.Cancel = !mItsMeClosingIt;
|