简体   繁体   English

如何在C#中自动对按钮单击进行文本框验证

[英]How to cause textbox validation on button click automatically in c#

Windows Form Application C# Windows 窗体应用程序 C#

I have four TextBox on windows Form .我在 windows Form上有四个TextBox i have written code to handle Text_Validating event for each textbox.我已经编写了代码来处理每个文本框的Text_Validating事件。 Now when user clicks on submit Button i want those text_validating events to fire automatically.现在,当用户单击提交Button时,我希望那些 text_validating 事件自动触发。

Enabled CausesValidation property of Button.已启用 Button 的CausesValidation属性。

We have something called validationGroup Property in ASP.net how it can be implemented in windows application我们在 ASP.net 中有一个叫做 validationGroup 属性的东西,它是如何在 Windows 应用程序中实现的

pls help me to solve this problem请帮我解决这个问题

thank you谢谢你

一种选择是简单地调用传入必要参数的验证方法(空值可能会起作用 - 显示代码将有助于确定是否有必要)。

I believe the Text_Validating event only fires when a control's focus changes.我相信 Text_Validating 事件仅在控件的焦点更改时触发。 If you are interested in validation on submit you could do something which is proposed by user Bruce from this post.如果您对提交验证感兴趣,您可以执行用户 Bruce 在这篇文章中提出的建议。

Also, you can write own Validator controls like asp.net in Winforms with following validators:- .此外,您可以使用以下验证器在Winforms中编写自己的验证器控件,如 asp.net:-。

RequiredFieldValidator  
RegularExpressionValidator  
CompareValidator    
RangeValidator  
CustomValidator

Here is a step by step explanation and walkthrough on how to extend Winforms with a custom validation library - http://msdn.microsoft.com/en-us/library/ms950965.aspx这是关于如何使用自定义验证库扩展 Winforms 的分步说明和演练 - http://msdn.microsoft.com/en-us/library/ms950965.aspx

On button click, go with:单击按钮时,请使用:

if(ValidateChildren())
{
      //do stuff
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM