2

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?

3
  • 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. Commented Feb 8, 2016 at 16:12
  • 1
    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. Commented Feb 8, 2016 at 16:12
  • 1
    ...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. Commented Feb 8, 2016 at 16:18

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.