日期:2014-05-17  浏览次数:21041 次

反射清除所有事件问题.button可以EventClick找到,NumericUpDown的事件找不到.
Button的Click事件.我用EventClick找到了所有Delegate.
NumericUpDown的ValueChanged事件.我用EventValueChanged找不到Delegate.
怎么办.
用的是以前高手写的方法.
希望各位大神赐教。
 public static Delegate[] GetObjectEventList<T>(T p_Control, string p_EventName)
       {
           PropertyInfo _PropertyInfo = p_Control.GetType().GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic);
           if (_PropertyInfo != null)
           {
               object _EventList = _PropertyInfo.GetValue(p_Control, null);
               if (_EventList != null && _EventList is EventHandlerList)
               {
                   EventHandlerList _List = (EventHandlerList)_EventList;
                   FieldInfo _FieldInfo = (typeof(Control)).GetField(p_EventName, BindingFlags.Static | BindingFlags.NonPublic);
                   if (_FieldInfo == null) return null;
                   Delegate _ObjectDelegate = _List[_FieldInfo.GetValue(p_Control)];
                   if (_ObjectDelegate == null) return null;
                   return _ObjectDelegate.GetInvocationList();
               }
           }
           return null;
       }

或者有其他方法清除所有ValueChanged事件的委托也可以.
events

------解决方案--------------------
你跟踪一下ValueChanged事件时什么类型?
可能不是EventHandlerList类型吧,你监控一下看看
------解决方案--------------------
那个时间的名字不对。肯定不是叫这个
跟button的不一样。