Win Form.Close Handler

  • Thread starter Thread starter Looch
  • Start date Start date
L

Looch

Hi All,

How can I add a handler to the closing of a windows form if the user
selects the 'X' in the upper right hand corner of a form? Basically
I'd like to make sure that certain text boxes are filled in before the
form can be closed. I haven't had the need for handlers untill now so
I'm definately new at this!

Thanks in advance
 
Looch,

Have you taken a look at the Closing event on the Form class? If the
form isn't filled out the way you need it to be, you can cancel the
operation.

Also, you might want to look at the Validating event as well.
 
Nicholas said:
Have you taken a look at the Closing event on the Form class? If the
form isn't filled out the way you need it to be, you can cancel the
operation.

As of .NET 2.0 (I believe), the FormClosing event is the preferred event
to use.
Also, you might want to look at the Validating event as well.

Agreed. Each control can raise a Validating event, and the handler for
that event can indicate the control isn't valid, preventing the form
from closing.

Pete
 

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

Back
Top