如何在Windows窗体中模仿JavaScript的onBlur事件? [英] How to mimic JavaScript's onBlur event in Windows Forms?
问题描述
我在Windows窗体上有电话和电子邮件文本框,我想在用户离开字段时进行验证。
I have phone and email textboxes on a Windows Form that I want to validate when the user leaves the fields.
当我双击Visual Studio表单中的文本框时设计师,它创建一个 textchanged
事件。这不太适合于仅当用户完成输入完整的条目时才调用验证方法,而不是在每次击键之后调用验证方法。
When I double click the textbox in Visual Studio form designer, it creates a textchanged
event. This 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.
有没有办法这个类似于JavaScript中的 onBlur
事件?
Is there a way to do this similar to onBlur
event in JavaScript?
我尝试过 MouseLeave
, Off Focus
,它们都像 TextChanged
。
I have tried MouseLeave
, Off Focus
, and they all act like TextChanged
.
如何做?
推荐答案
尝试离开
事件。浏览到您的控件的属性页面。
Try the Leave
event. Navigate to the Property page for your control.
您可以直接键入要创建的方法的名称。按输入,Visual Studio将为您创建方法。
You can simply type the name of the method you'll be creating. Press Enter and Visual Studio will create the method for you.
这篇关于如何在Windows窗体中模仿JavaScript的onBlur事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!