zoukankan      html  css  js  c++  java
  • 怎么判断事件是否已订阅某一方法

    1用反射

                PropertyInfo pi = (typeof(Button)).GetProperty("Events",
                    BindingFlags.Instance | BindingFlags.NonPublic);
                EventHandlerList ehl = (EventHandlerList)pi.GetValue(btnHardInfo, null);//这是你的Button
                FieldInfo fi = (typeof(Control)).GetField("EventClick",
                    BindingFlags.Static | BindingFlags.NonPublic);
                Delegate d = ehl[fi.GetValue(null)];
                if (d != null)
                {
                    System.Delegate[] dels = d.GetInvocationList();
                    for (int i = 0; i < dels.Length; i++)
                    {
                        MsgBox.Items.Add(dels[i].Method.Name);//这里会输出所有方法名称
                    }
                }
    

      

    2只要在加事件之前先-=就可以了

    button2.Click -= new EventHandler(button2_Click);
    button2.Click += new EventHandler(button2_Click);

  • 相关阅读:
    【bzoj1010】[HNOI2008]玩具装箱toy
    bzoj 3173
    bzoj 1179
    bzoj 2427
    bzoj 1051
    bzoj 1877
    bzoj 1066
    bzoj 2127
    bzoj 1412
    bzoj 3438
  • 原文地址:https://www.cnblogs.com/sinceret/p/11393565.html
Copyright © 2011-2022 走看看