WinForms 中的用户输入验证
我在 WinForms 应用程序中创建了一些表单,并希望实现用户输入的验证。有几个组合框和文本框。我必须检查某些字段不为空,并且某些字段需要十进制数字格式。我知道有企业库验证块
和集成的ErrorProvider
。您对集成速度有何建议?
提前致谢。
I'm created a few forms in WinForms application and want to implement validation of user input. There are several ComboBox'es and TextBox'es. I have to check that some fields are not empty and some field require decimal number format. I know there are Enterprise Library Validation Blocks
and integrated ErrorProvider
. What way can you advice in terms of integration’s speed.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在没有企业库的情况下完成此任务,除非您的应用程序确实是企业应用程序。
如果您引用 System.Windows.Forms.ErrorProvider 那么这将是最快的方法。是一个非常简单的组件,但我不进行验证,只是视觉辅助。因此,您必须“手动”进行验证。
You can do this task without enterprise library, unless your application is really an Enterprise application.
If you are refering to System.Windows.Forms.ErrorProvider then this would be the fastest way. Is a very simple component but I does not make validation, just visual aid. So you will have to do the validation "manually".
我有一个自定义类,其中定义了方法。我还利用委托来触发任何事件的方法。
已编辑**
本文可能有所帮助:C# 验证 TextBox 控件
I have a custom class where in methods are defined. I also make use of delegates to fire a method on any event.
Edited **
This article might help: C# Validating TextBox Control
我认为最好的方法是使用 正则表达式
您可以在每个元素失去焦点时调用验证,就像某些 Web 表单一样。
I think the best way is to use regular expressions
You can call the validation when each element loses focus, just like some web forms.