这3个的委托怎么取消,谁帮我写下方法哦! http://bbs.csdn.net/topics/390663596?page=1#post-396282834 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 楼上的回复足以结贴咯。试一下以下语句的效果: button13.Click-=new EventHandler(delegate{MessageBox.Show("1");}); button13.Click -= delegate{MessageBox.Show("1");}; 不用匿名委托怎么写,又如何批量取消?定义一个委托(事件是一种特殊的委托),然后就可以+=和-=的操作了。如下: EventHandler pro; pro = (sender, e) => { //....... }; button13.Click += pro;如果要批量删除,可以像你现在这样用匿名委托。通过反射遍历找到它的所有事件,Remove掉 看了,有点深奥,特别是这段代码PropertyInfo _PropertyInfo = p_Object.GetType().GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic); if (_PropertyInfo != null) { object _EventList = _PropertyInfo.GetValue(p_Object, null); if (_EventList != null && _EventList is EventHandlerList) { EventHandlerList _List = (EventHandlerList)_EventList; FieldInfo _FieldInfo = p_EventType.GetField(p_EventName, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.IgnoreCase); if (_FieldInfo == null) return null; Delegate _ObjectDelegate = _List[_FieldInfo.GetValue(p_Object)]; if (_ObjectDelegate == null) return null; return _ObjectDelegate.GetInvocationList(); } } return null; 特别是这些句子,有点云里雾里的感觉PropertyInfoobject _EventList = _PropertyInfo.GetValue(p_Object, null);FieldInfo _FieldInfo = p_EventType.GetField(FieldInfo _FieldInfo = p_EventType.GetField(Delegate _ObjectDelegate = _List[_FieldInfo.GetValue( 看了,有点深奥,特别是这段代码PropertyInfo _PropertyInfo = p_Object.GetType().GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic); if (_PropertyInfo != null) { object _EventList = _PropertyInfo.GetValue(p_Object, null); if (_EventList != null && _EventList is EventHandlerList) { EventHandlerList _List = (EventHandlerList)_EventList; FieldInfo _FieldInfo = p_EventType.GetField(p_EventName, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.IgnoreCase); if (_FieldInfo == null) return null; Delegate _ObjectDelegate = _List[_FieldInfo.GetValue(p_Object)]; if (_ObjectDelegate == null) return null; return _ObjectDelegate.GetInvocationList(); } } return null;一个是反射,懂不懂?另一个涉及到WinForms的EventHandlerList机制,简单来说,因为对于控件来说,有大量的事件,为了减少存储提高性能,WinForms将它们全部存入一个列表,类似字典,这样绝大部分没有挂钩事件处理函数的事件就不要单独存储了。实在不理解,你就当黑盒直接用吧。 Web TreeView 连续点击同一节点 请教的Process.Start()问题 自学C#的又来请教 (IMP2P通信求助)我是新学的通信现在网上找了些方法写点代码不好使 C#/C++中如何嵌入汇编指令? log4net 日志文件名 treeview中节点多的时候显示的问题 c# 写txt文件 我发现了一个奇怪的问题,如何判断DataTable的是否为空?大家来研究一下吧 to:hgknight(江雨.net) 關於直接显示TreeView的简单问题!! 引用类型变成值类型 在线急等,c#如何用操作数据库的模式来操作excel, 求大神指点~
button13.Click-=new EventHandler(delegate{MessageBox.Show("1");});
EventHandler pro;
pro = (sender, e) =>
{
//.......
};
button13.Click += pro;
如果要批量删除,可以像你现在这样用匿名委托。通过反射遍历找到它的所有事件,Remove掉
if (_PropertyInfo != null)
{
object _EventList = _PropertyInfo.GetValue(p_Object, null);
if (_EventList != null && _EventList is EventHandlerList)
{
EventHandlerList _List = (EventHandlerList)_EventList;
FieldInfo _FieldInfo = p_EventType.GetField(p_EventName, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.IgnoreCase);
if (_FieldInfo == null) return null;
Delegate _ObjectDelegate = _List[_FieldInfo.GetValue(p_Object)];
if (_ObjectDelegate == null) return null;
return _ObjectDelegate.GetInvocationList();
}
}
return null;
PropertyInfo
object _EventList = _PropertyInfo.GetValue(p_Object, null);
FieldInfo _FieldInfo = p_EventType.GetField(
FieldInfo _FieldInfo = p_EventType.GetField(
Delegate _ObjectDelegate = _List[_FieldInfo.GetValue(
if (_PropertyInfo != null)
{
object _EventList = _PropertyInfo.GetValue(p_Object, null);
if (_EventList != null && _EventList is EventHandlerList)
{
EventHandlerList _List = (EventHandlerList)_EventList;
FieldInfo _FieldInfo = p_EventType.GetField(p_EventName, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.IgnoreCase);
if (_FieldInfo == null) return null;
Delegate _ObjectDelegate = _List[_FieldInfo.GetValue(p_Object)];
if (_ObjectDelegate == null) return null;
return _ObjectDelegate.GetInvocationList();
}
}
return null;
一个是反射,懂不懂?另一个涉及到WinForms的EventHandlerList机制,简单来说,因为对于控件来说,有大量的事件,为了减少存储提高性能,WinForms将它们全部存入一个列表,类似字典,这样绝大部分没有挂钩事件处理函数的事件就不要单独存储了。
实在不理解,你就当黑盒直接用吧。