自动验证中的WinForms在一个专用的标签 [英] Auto validation in Winforms in a dedicated label

查看:110
本文介绍了自动验证中的WinForms在一个专用的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了在某些地方(抱歉,我无法提供的那一刻链接)的形式验证错误显示在顶部的标签。当用户填写了表格,该错误文本相应的变化。

I have seen in certain places (sorry, am unable to provide links at the moment) that validation errors in a form are displayed in a label at the top. As the user fills up the form, that error text changes accordingly.

我可以看到一个明显的,如果... else和处理验证等事件来实现这一(尽管它可以变成是非常繁琐复杂的形式)。有没有更简单的,更清洁的方式做到这一点?

I can see an obvious if...else and handling "Validating" etc events to implement this (though it can turn out to be very tedious for complex forms). Is there a more straightforward, cleaner way to do this?

谢谢!

推荐答案

您应该考虑实施 IDataErrorInfo 在<一个描述href="http://www.$c$cgod.de/WebApp$c$cGod/objectdatasource-and-idataerrorinfo-with-winforms-AID427.aspx"相对=nofollow>这个博客帖子。然后,您可以绑定你的标签 IDataErrorInfo.Error 属性。加入少许 INotifyPropertyChanged的和您的标签将更新自动神奇。

You should look into implementing IDataErrorInfo as described in this blog post. You can then bind your Label to the IDataErrorInfo.Error property. Add a little INotifyPropertyChanged and your Label will update auto-magically.

这篇关于自动验证中的WinForms在一个专用的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆