单击取消按钮时禁用错误提供者的验证
当单击“取消”按钮关闭 winform 时,有没有办法优雅地禁用 errorprovider 的验证? 当文本框失去焦点时,验证总是发生,我不希望它在用户单击取消按钮时进行验证,当用户单击取消时进行验证有点愚蠢。
is there a way to disable the validation of errorprovider elegantly when click cancel button to dismiss a winform?
The validation always happens when the textbox lose focus, and i don't wanna it to validate when the user click cancel button, it is just a little bit silly to validate when the user clicking cancel.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
谷歌搜索后,找到了答案,只需将取消按钮的 CauseValidation 属性设置为 false 即可。就是这样。
after googling, found the answer, just set CauseValidation property of the cancel button to false. that's it.
我自己刚刚遇到了这个问题,设置
CauseValidation = false
只是部分解决方案。当您将
Form.CancelButton
设置为取消按钮时,Escape 键应该调用该按钮。然而,即使我们设置了CauseValidation = false,验证仍然会运行以响应Escape 键。要修复它,请添加以下 hack:
I just ran into this myself and setting
CauseValidation = false
is only a partial solution.When you set the
Form.CancelButton
to the cancel button, the Escape key is supposed to invoke that button. It does, however, validation still runs in response to the Escape key, even though we setCauseValidation = false
.To fix it, add the following hack: