What is the event to trap when user clicks X to close form?

  • Thread starter Thread starter Robert Dufour
  • Start date Start date
R

Robert Dufour

On my form if the user clicks the upper right hand corner to close the form
I want to trap that event and do a check to see if closing is allowed, if
not, I want to stop the form closing action.

Can anyone tell me how I can do this?

Thanks for any help
Bob
 
Robert Dufour said:
On my form if the user clicks the upper right hand corner to close the
form I want to trap that event and do a check to see if closing is
allowed, if not, I want to stop the form closing action.

In addition to the other replies:

If you are using .NET 2.0, check out the form's 'FormClosing' event too.
 
There is also the option to override the WndProc method if you really
needed to.

Thanks,

Seth Rowe
 
On my form if the user clicks the upper right hand corner to close the form
I want to trap that event and do a check to see if closing is allowed, if
not, I want to stop the form closing action.

Can anyone tell me how I can do this?

Thanks for any help
Bob

In VB6, there was the QueryUnload event which had an UnloadMode argument, one of
which was vbFormControlMenu which was specific to the "X" button and the control
menu, "Close".

In .Net, AFAIK, there is no functional equivalent short of using the WndProc method.
FormClosing event will fire when the "X" button is pressed (3-User Closing), but it
also fires for the same reason if Me.Close() is called - 3-User Closing.

Gene
 
Thank you all

gene kelley said:
In VB6, there was the QueryUnload event which had an UnloadMode argument,
one of
which was vbFormControlMenu which was specific to the "X" button and the
control
menu, "Close".

In .Net, AFAIK, there is no functional equivalent short of using the
WndProc method.
FormClosing event will fire when the "X" button is pressed (3-User
Closing), but it
also fires for the same reason if Me.Close() is called - 3-User Closing.

Gene
 
Back
Top