if you have a combobox dropped, pressing escape should close the combobox and not exit the dialog, which the above code will do.

It would be possible to exempt certain control types on the escape key event but that's not a good solution, it's just a matter of time until another control that uses escape internally is introduced into the form, e.g.

c validating close form-13c validating close form-13c validating close form-61

However, pressing Escape to cancel the form does not perform the same as pressing the Cancel button - it raises the Validating event and prevents the user from exiting. You can press the Cancel button or close the form directly even if there are 3 characters present; however pressing the Escape key will not do the same - it fires the Validating event whereas it should be doing the same as pressing Cancel.

Is there any way of making the Escape key perform as intended, i.e. I just saw this problem as I was hunting a solution for the same and the override of Processdialog Key is the MS-approved solution until they fix the bug (Escape should do the same as clicking Cancel).

And I find that extremely annoying, just to give an example, if I open this winform, and then immediately try to close it, it is not going to let me, because the validation will trigger complaining that the first textbox have no text entered.

The behavior I want is using the errorprovider, how can I validate the whole form only when I click the Save button of the form?

If you do this lots, you can refactor the validation into a base form with an Error Provider and inherit from it.

This would disable the validation when I enter the button to click, then when clicked the cancel buttons click event can be fired and I can do whatever logic that is needed in there, including clearing the errors.

Does anyone know what the idea behind that is, because it's not a bug... Perform Click then you would be closer to a solution since it would be up to someone else to determine what to do with the escape key.

But setting Auto Validate to Disabled here and then returning it to it's original value doesn't prevent the validation since it, probably do to simply posting events and places a message on the queue, doesn't use that value until after it has been set back to it's original value.

EDIT: presently as a work around, I have a method that toggles the "Causes Validation" property on and off. It has to be set on the parent form and suppresses the validating event when a control is losing focus.

I default everything to not Cause Validation, enables them all before I use the event for validating the whole form, and disables them all after again. I think this is the best way to go with validation using Error Provider Component (Or) Try this I've used something along the following lines: 1) Define the controls you want validated in a collection of some sort.

The Validating event occurs when a control yields focus to another control.