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?
Asked
Active
Viewed 429 times
2
-
1In 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 Feb 08 '16 at 16:12
-
1I 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 Feb 08 '16 at 16:12
-
1...and even if you dont use a `DateTimePicker` there is no reason to be so restrictive. `DateTime` can [parse](https://dotnetfiddle.net/WImdZ7) can parse from any legal format for a culture. – Ňɏssa Pøngjǣrdenlarp Feb 08 '16 at 16:18
1 Answers
3
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

Community
- 1
- 1

Matt Wilko
- 26,994
- 10
- 93
- 143