开发者

How to mimic JavaScript's onBlur event in Windows Forms?

开发者 https://www.devze.com 2022-12-16 06:52 出处:网络
I have phone and email textboxes on a Windows Form that I want to validate when the user leaves the fields.

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.

How to mimic JavaScript's onBlur event in Windows Forms?

How to mimic JavaScript's onBlur event in Windows Forms?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消