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

C#动态删除所有的鼠标点击事件

C#删除所有的鼠标点击事件~~

其中的sender 为控件对象

?

?

           FieldInfo keyfi = typeof(Control).GetField("EventClick", BindingFlags.Static | BindingFlags.NonPublic);
            object eventkey = keyfi.GetValue(sender);
            // Get the protected Events property 
            PropertyInfo evtpi = typeof(Control).GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic);
            EventHandlerList evts = (EventHandlerList)evtpi.GetValue(sender, null);
            // Obtain the value of the delegate and remove it 
            Delegate dlg = evts[eventkey];
            evts.RemoveHandler(eventkey, dlg);
?

?