[英]How to raise a validation event from a key press
I want to raise the: 我想提出:
private void txtbox_startdate_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{}
Function from a key leave event. 离开键事件的功能。 The leave event looks like:
离开事件看起来像:
private void txtbox_startdate_Leave(object sender, EventArgs e)
{}
The trouble is of course if I try and call it in this manner: 如果我尝试以这种方式调用它,当然会遇到麻烦:
txtbox_startdate_Validating(sender, e)
An error is raised because in this case e
is an EventArg
s whereas the validation function wants a System.ComponentModel.CancelEventArgs
and so, how do I convert EventArgs
to a System.ComponentModel.CancelEventArgs
or create one so that I can call my validation function? 出现错误是因为在这种情况下
e
是EventArg
而验证函数需要System.ComponentModel.CancelEventArgs
,因此,如何将EventArgs
转换为System.ComponentModel.CancelEventArgs
或创建一个以便我可以调用验证函数?
See MSDN: 请参阅MSDN:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.validating.aspx http://msdn.microsoft.com/zh-CN/library/system.windows.forms.control.validating.aspx
You have no need to call the txtbox_startdate_Validating
event (or any other control with a validating event) from the txtbox_startdate_Leave
event as it's the order of the events to go from one to another as part of the design. 您不必调用
txtbox_startdate_Validating
从事件(或任何其它控制与验证事件) txtbox_startdate_Leave
事件,因为它是事件的顺序从一个到另一个去作为设计的一部分。
normally whatever the validator is, you can just call Validate() on it instead of doing this. 通常,无论验证器是什么,您都可以对其调用Validate()而不是这样做。
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.basevalidator.validate.aspx http://msdn.microsoft.com/zh-CN/library/system.web.ui.webcontrols.basevalidator.validate.aspx
Otherwise, just 'new' the canceleventargs yourself - it's not special, the constructors are public. 否则,您自己可以自己“新建” canceleventargs-并不特殊,构造函数是公共的。
http://msdn.microsoft.com/en-us/library/system.componentmodel.canceleventargs.canceleventargs.aspx http://msdn.microsoft.com/zh-CN/library/system.componentmodel.canceleventargs.canceleventargs.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.