Click here to Skip to main content
15,895,815 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
I am using vb.net form. I was wondering if there is an event (or way ) that check if when the user click the close form button?

If yes, can you also cancel the form from closing ?
Posted

Yes, there is a way, oddly enough, its called the FormClosing event, and you just need to intercept it.

FormClosing Event[^] on MSDN has a good reference for how to use it.
 
Share this answer
 
v2
Yes, and yes.
Handle the Form.FormClosing event, and it will give you a FormClosingEventArgs as a parameter.
This contains a property CloseReason[^] which gives you as much info as you are going to get, and also has a Cancel[^] property that you can set to True if you want to prevent it closing.
Note: if you always cancel the Form Close, you will seriously annoy your users! Provide some mechanism for them to get out...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900