2
votes

I'm sure this question can apply to both, although I'm usually working with VB6 code, but why use Lost Focus vs Validate? As an example, say I need a date entered in a text box for date of birth, i want to make sure that date is entered in mm/dd/yyyy format, why would I choose to go with Validate vs Lost Focus?

1
In addition to Matt's answer, field by field validation isnt practical in many apps. Validation of one control may depend on the value of another, or involve complex business rules.Ňɏssa Pøngjǣrdenlarp
I use Validate when I want to do some validation on the text and possibly PREVENT the user from moving away from the control. I generally avoid Lost Focus but might use it to adjust some trivial visual aspect of the control, like changing back colour to show where the focus is.Andrew Mortimer
...and even if you dont use a DateTimePicker there is no reason to be so restrictive. DateTime can parse can parse from any legal format for a culture.Ňɏssa Pøngjǣrdenlarp

1 Answers

3
votes

Lost focus only fires when the user moves focus from that control to another one. The validated event fires at the point of validation. More info on validation here: WinForm UI Validation

Note that you should use a datetimepicker for date entry; that way you do not have to worry amount the format entered as it's value property is a date