[英]How do I programatically raise an existing event within a custom control?
I have made a custom class by inheriting a DateTimePicker and made some methods that allow it to be blank/null. 我通过继承DateTimePicker制作了一个自定义类,并做了一些使它为空/空的方法。
If the control is blank and a user clicks on it, it populates with the current date. 如果控件为空白,并且用户单击它,则会使用当前日期填充该控件。 It also raises the
ValueChanged
event. 它还引发
ValueChanged
事件。
If the control is populated and a user presses delete, it clears and sets its value to null, but the ValueChanged
event doesn't trigger. 如果已填充控件,并且用户按Delete键,则它将清除并将其值设置为null,但不会触发
ValueChanged
事件。
In the control's OnKeyDown
method, I would like to include some code that raises the ValueChanged
event, but there doesn't seem to be a way to do that. 在控件的
OnKeyDown
方法中,我想包含一些引发ValueChanged
事件的代码,但似乎没有办法做到这一点。
Do I need to override the base class event? 我需要覆盖基类事件吗? Is there an applicable example?
有适用的例子吗?
DateTimePicker.OnValueChanged将引发ValueChanged事件。
You have to call/override DateTimePicker.OnValueChanged()
. 您必须调用/重写
DateTimePicker.OnValueChanged()
。 This method calls the event, so you can implement your code through this. 此方法调用事件,因此您可以通过此方法实现代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.