日期:2014-05-17 浏览次数:21050 次
System.ComponentModel.EventHandlerList list= this.Events;
------解决方案--------------------
Delegate.RemoveAll(ChangeName);
------解决方案--------------------
System.Web.UI.WebControls.Label label = new System.Web.UI.WebControls.Label(); System.Reflection.EventInfo[] events= label.GetType().GetEvents();
------解决方案--------------------
关注 帮顶~
------解决方案--------------------
如果控制一个委托事件里同样的方法只注册一次?
与这个问题是类似的,GetInvocationList获取所有的事件处理函数:
Delegate[] allDlg = new Delegate[this.UpdateFax.GetInvocationList().GetLength(0)]; this.UpdateFax.GetInvocationList().CopyTo(allDlg, 0); foreach (Delegate dlg in allDlg) { if (dlg.Method.Name == "Form1_UpdateFax") { //不在绑定 } else { //绑定 UpdateFax += new UpdateFaxEventHander(Form1_UpdateFax); MessageBox.Show("绑定成功"); } }
------解决方案--------------------
想到:循环委托列表,一一进行取消.
我去试下...
------解决方案--------------------
public delegate void ChangeProperty(); public class A { // 自定义事件 public event ChangeProperty ChangeName; public void Test() { OnChangeName(); } protected virtual void OnChangeName() { if (ChangeName != null) ChangeName(); } public void ReMove() { ChangeProperty temp = null; foreach (Delegate d in ChangeName.GetInvocationList()) { temp = (ChangeProperty)d; ChangeName -= temp; } } }
------解决方案--------------------
获取委托列表,直接给列表清空或释放试试
------解决方案--------------------
你自己需要维护一个监听器
http://book.51cto.com/art/200809/90512.htm
------解决方案--------------------
路过,学习下
------解决方案--------------------
路过看看
------解决方案--------------------
发射法:
//test code begin A a = new A(); a.ChangeName+=delegate(){ Console.WriteLine("ChangeName 1"); }; a.ChangeName+=delegate(){ Console.WriteLine("ChangeName 2"); }; a.ChangeName+=delegate(){ Console.WriteLine("ChangeName 3"); }; a.DoChangeName(); //test code end FieldInfo fi = typeof(A).GetField("ChangeName",BindingFlags.NonPublic | BindingFlags.Instance); Delegate del = fi.GetValue(a) as Delegate; foreach (Delegate value in del.GetInvocationList())