有一个方法来禁用ErrorProvider控件的验证典雅当单击取消按钮以关闭一个winform? 验证总是发生在文本框失去焦点,我也不当用户点击取消按钮想它来验证,它仅仅是一个有点傻,以验证当用户点击取消。

有帮助吗?

解决方案

谷歌搜索后,找到了答案,的取消按钮,以假刚刚集合CauseValidation属性。就是这样。

其他提示

我只是遇到这个自己和设置CauseValidation = false只是部分解决方案。

在设置Form.CancelButton到取消按钮,Escape键应该调用该按钮。它,然而,验证仍然运行响应Escape键,即使我们设置CauseValidation = false

要解决它,添加以下劈:

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
    // Although we set CausesValidation = false for the Cancel button,
    //  the Escape key fails to cancel due to validation failure. The
    //  Form.CancelButton property should invoke the validation-free
    //  cancel button, but doesn't. Force the issue here.
    if (keyData == Keys.Escape)
    {
        DialogResult = DialogResult.Cancel;
        return true;
    }
    return base.ProcessCmdKey(ref msg, keyData);
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top