简体   繁体   English

使用事件检查文本框中的字符串?

[英]Check string in textbox with an event?

我想知道在用户点击OK按钮之前是否有办法使用事件来检查Windows窗体中textBox中的字符串?

You can use the KeyDown, KeyPress, or KeyUp event. 您可以使用KeyDown,KeyPress或KeyUp事件。

A full list of events can be found here: http://msdn.microsoft.com/en-us/library/system.windows.forms.textbox_events.aspx 可以在此处找到完整的事件列表: http//msdn.microsoft.com/en-us/library/system.windows.forms.textbox_events.aspx

It's all alphabetical, so scroll down to Key.... 这都是按字母顺序排列的,所以向下滚动到Key ....

A better approach is to use the Validating event of the textbox. 更好的方法是使用文本框的Validating事件。 This way, your validation routine runs when the user attempts to leave the textbox. 这样,当用户尝试离开文本框时,您的验证例程就会运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM