关闭框触发对非模式形式的验证 [英] Close box triggers validation for non-modal form

查看:55
本文介绍了关闭框触发对非模式形式的验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个从公共基础继承的表单类。其中一种形式称为模态形式,另一种形式称为非模态形式。焦点更改时需要验证,但取消表单时不需要验证。在模式窗体上选择关闭框后,它会正确关闭,而不会在控件上触发任何验证。在非模式窗体上选择关闭框时,将触发验证事件。在两种情况下,将CausesValidation设置为false的Cancel按钮在两种情况下都可以正常工作。

I have two form classes inheriting from a common base. One of the forms is called modally and the other non-modally. Validation is required on focus changes but not when the form is cancelled. When the Close Box is selected on the modal form it closes properly without any validation being triggered on it's controls. When the Close Box is selected on the non-modal form, validation events are triggered. A Cancel button with CausesValidation set false works fine in both cases.

我尝试将非模式窗体上的CausesValidation设置为false,但问题仍然存在。我应该提到表格是mdi儿童。

I have tried setting CausesValidation on the non-modal form to false but the problem remains. I should mention that the forms are mdi children.

有什么想法吗?

Thx。

推荐答案

将非模式形式的 AutoValidate属性设置为 Disable。这样可以防止Form隐式验证所有子控件。

Set the "AutoValidate" property of the non-modal form to "Disable". This will prevent the Form from implicitly validating all child controls.

但是,稍后,如果您需要验证所有子控件,则可以使用Form.ValidateChildren()方法。 。这将强制验证所有包含的子控件。

However, at a later time if you require to validate all child controls you can use Form.ValidateChildren() method. That will force validation for all contained child controls.

这篇关于关闭框触发对非模式形式的验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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