Hi!

When setting e.Cancel = true in a forms Closing event, you can prevent
the form being closed. I did so, but on my form I have a button with
DialogResult set to Abort, but the form doesn't close now that I've set
Cancel to true.

How can I work around this so that you cannot close the form by using
Alt-F4 but still allow the controls to call the Close method of the form?

Thanks in advance,
Patrick

Re: Cancel form closing by hirf-spam-me-here

hirf-spam-me-here
Sun Oct 12 07:39:45 CDT 2003

* Patrick Kristiansen <patrick@sixulon.dk> scripsit:
> When setting e.Cancel = true in a forms Closing event, you can prevent
> the form being closed. I did so, but on my form I have a button with
> DialogResult set to Abort, but the form doesn't close now that I've
> set Cancel to true.
>
> How can I work around this so that you cannot close the form by using
> Alt-F4 but still allow the controls to call the Close method of the
> form?

Remove the 'DialogResult' from the button and add this code in its
'Click' event handler:

\\\
m_Close = True
Me.DialogResult = DialogResult.Abort
Me.Close()
///

On top of the code you add:

\\\
Private m_Close As Boolean
///

In the 'Closing' event handler you check 'm_Close' and set 'e.Cancel' to
'True' only if it is not set.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>