简体   繁体   English

在以下情况下,如何为自定义控件创建名为valuechanged的自定义事件

[英]How can I create a custom event named valuechanged for a custom control when

... when the custom control includes a slider which has alsready a valuechanged event : seems the form that contains the custom control never receives that event, I have to change it to another name. ...当自定义控件包括一个已经发生了valuechanged事件的滑块:似乎包含自定义控件的窗体从未收到该事件,我必须将其更改为另一个名称。

Is there a way to circumvent this: seems rather stupid that I have a valuechanged name for a custom control. 有没有办法避免这种情况:我为自定义控件设置了值更改名称似乎很愚蠢。

A ValueChanged event declared in bite the spider control and your custom control will not be in conflict. 叮咬蜘蛛控件中声明的ValueChanged事件和您的自定义控件不会发生冲突。 They will belong to two different instances. 它们将属于两个不同的实例。

Now, the custom event will not fire automatically, even though the slider event fires. 现在,即使触发了滑块事件,自定义事件也不会自动触发。 You will have to add an event handler, internal to the custom control, handling the slider event. 您将必须在自定义控件内部添加事件处理程序,以处理滑块事件。 The handler should raise the custom event, this propagating the slider event to the container. 处理程序应引发自定义事件,这会将滑块事件传播到容器。

I could solve my problem by the tutorial of MSDN (http://msdn.microsoft.com/en-us/library/w369ty8x.aspx). 我可以通过MSDN教程(http://msdn.microsoft.com/zh-cn/library/w369ty8x.aspx)解决问题。 I found out that because of previous considerations, my event publisher class called ButtonMenu was a singleton, which is no more needed. 我发现由于先前的考虑,我的事件发布者类ButtonButton是单例,因此不再需要。 So, I modified it to a normal control class. 因此,我将其修改为常规控件类。 I added all what is said in the MSDN site, and it worked properly! 我添加了MSDN站点中的所有内容,并且一切正常!

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

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