form cancel validation behavior

G

Guest

I've got a form with OK/Cancel buttons and a control box "X" button. Cancel
is fully wired with DialogResult and all that jazz.

There is a textbox on the form with a Validating event.
The Cancel button has CausesValidation = false.

If I click the Cancel button, validation is skipped and everything's fine.
However, if I hit the escape key or alt-C (Cancel mnemonic), validation
still takes place. It's behaving as if these latter two methods (escape and
alt-C) are interally causing the textbox to lose focus and thus validate
before the cancel_click event fires.

Thoughts/comments?
 
G

Guest

The validation controls for windows forms are woefully inadequate. There is
no way to override them when you want to click the cancel button.

A better solution was laid out in a multi-part series on msdn:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms05182004.asp

The use of modal forms, I feel, is too tricky to be quickly implemented with
accuracy. If you are simply presenting a messagebox, then their use is fine.

Ideally, you should use events and delegates to notify your application of
windows closing and opening. You can also capture data changes and any other
events you can think of.

You can even disable the parent form when you open a child form and re
enable it on the child forms closing.
 

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