[英]c# - XAML: how to open an menu with textbox and button by button click?
[英]How to cause textbox validation on button click automatically in c#
Windows 窗体应用程序 C#
我在 windows Form
上有四个TextBox
。 我已经编写了代码来处理每个文本框的Text_Validating
事件。 现在,当用户单击提交Button
时,我希望那些 text_validating 事件自动触发。
已启用 Button 的CausesValidation
属性。
我们在 ASP.net 中有一个叫做 validationGroup 属性的东西,它是如何在 Windows 应用程序中实现的
请帮我解决这个问题
谢谢你
一种选择是简单地调用传入必要参数的验证方法(空值可能会起作用 - 显示代码将有助于确定是否有必要)。
我相信 Text_Validating 事件仅在控件的焦点更改时触发。 如果您对提交验证感兴趣,您可以执行用户 Bruce 在这篇文章中提出的建议。
此外,您可以使用以下验证器在Winforms
中编写自己的验证器控件,如 asp.net:-。
RequiredFieldValidator
RegularExpressionValidator
CompareValidator
RangeValidator
CustomValidator
这是关于如何使用自定义验证库扩展 Winforms 的分步说明和演练 - http://msdn.microsoft.com/en-us/library/ms950965.aspx
单击按钮时,请使用:
if(ValidateChildren())
{
//do stuff
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.