如何点击窗体的取消按钮后跳过验证 [英] How to skip Validating after clicking on a Form's Cancel button

查看:610
本文介绍了如何点击窗体的取消按钮后跳过验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用C#。
我有一个编辑框和一个取消按钮的Windows窗体。编辑框在验证事件code。在code,每次执行编辑框失去焦点的时间。当我点击取消按钮我只是想关闭表单。我不想被执行编辑框任何验证。这怎么可能实现呢?

I use C#. I have a Windows Form with an edit box and a Cancel button. The edit box has code in validating event. The code is executed every time the edit box loses focus. When I click on the Cancel button I just want to close the form. I don't want any validation for the edit box to be executed. How can this be accomplished?

下面是一个重要的细节:如果验证失败,则

Here is an important detail: if the validation fails, then

            e.Cancel = true;

$ P $离开控制pvents。

prevents from leaving the control.

但是,当用户点击取消按钮,然后形式应该不管关闭。这可怎么实现的?

But when a user clicks Cancel button, then the form should be closed no matter what. how can this be implemented?

推荐答案

如果当编辑框失去焦点,避谈取消按钮会阻止这种情况发生时确认。

If the validation occurs when the edit box loses focus, nothing about the the cancel button is going to stop that from happening.

但是,如果验证失败是$ P $从做它的事pventing取消按钮,按钮的的CausesValidation 属性设置为

However, if the failing validation is preventing the cancel button from doing its thing, set the CausesValidation property of the button to false.

<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.causesvalidation.aspx\">Reference: Button.CausesValidation 属性

这篇关于如何点击窗体的取消按钮后跳过验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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