I have phone and email textboxes on a Windows Form that I want to validate when the user leaves the fields.
When I double click the textbox in Visual Studio form designer, it creates a textchanged
event. Thi开发者_StackOverflow中文版s isn't quite suitable as want to call the validate method only when the user is done entering the full entry, not after every keystroke.
Is there a way to do this similar to onBlur
event in JavaScript?
I have tried MouseLeave
, Off Focus
, and they all act like TextChanged
.
How can this be done?
Try the Leave
event. Navigate to the Property page for your control.
You can simply type the name of the method you'll be creating. Press Enter and Visual Studio will create the method for you.
The Validating event was designed to do this. Set e.Cancel = true if you're not happy with the input. The ErrorProvider component is ideal to provide visual feedback.
OnLostFocus, maybe?
There's an OnLostFocus
event for controls. You should be able to use that.
精彩评论