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

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
 
H

Herfried K. Wagner [MVP]

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.
 
R

rowe_newsgroups

There is also the option to override the WndProc method if you really
needed to.

Thanks,

Seth Rowe
 
G

gene kelley

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
 
R

rdufour

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top