我加入了一个事件处理这样的:如何确保没有处理程序附加到事件?
theImage.MouseMove += new MouseEventHandler(theImage_MouseMove);
,但在我的应用程序,该代码获取运行页面显示每次,所以我要附加的事件处理程序只一次 ,但我怎么能告诉我们,如果一个处理器已设置但还是不行,像这样:
if(theImage.MouseMove == null) //error
theImage.MouseMove += new MouseEventHandler(theImage_MouseMove);
Dupe:http://stackoverflow.com/questions/1129517/c-how-to-find-if-an-event-is-hooked-up – 2010-03-19 16:25:04
@Jason:爱德华只关心确保事件不是'不止一次,所以爱德华问题的解决方案是不同的。 – Brian 2010-03-19 16:33:22
@Brian::s/Dupe /相关 – 2010-03-19 16:37:46