zoukankan      html  css  js  c++  java
  • winform 事件清除

    static void ClearEvent(DataGridView pControl, string pEventName)

    {

    if (pControl == null) return;
    var controlType = pControl.GetType();
    var eName = ("EVENT_" + controlType.Name + pEventName).ToUpper();

    if (string.IsNullOrEmpty(pEventName)) return;

    BindingFlags mPropertyFlags = BindingFlags.Instance | BindingFlags.Public
    | BindingFlags.Static | BindingFlags.NonPublic;//筛选
    BindingFlags mFieldFlags = BindingFlags.Static | BindingFlags.NonPublic;

    PropertyInfo propertyInfo = controlType.GetProperty("Events", mPropertyFlags);

    EventHandlerList eventHandlerList = (EventHandlerList)propertyInfo.GetValue(pControl, null);//事件列表

    FieldInfo fieldInfo = controlType.GetField(eName, mFieldFlags);
    var fieldInfos = controlType.GetFields(mFieldFlags);
    Delegate d = eventHandlerList[fieldInfo.GetValue(pControl)];

    if (d == null) return;

    EventInfo eventInfo = controlType.GetEvent(pEventName);

    foreach (Delegate dx in d.GetInvocationList())

    eventInfo.RemoveEventHandler(pControl, dx);//移除已订阅的pEventName类型事件

    }

  • 相关阅读:
    2019hdu多校1
    codefroce842C
    [codeforce686D]树的重心
    [codeforce1188C&D]
    Educational Codeforces Round 66
    [hdu4343]interval query
    Luogu 4234 最小差值生成树
    BZOJ 2594 水管局长
    Luogu 2173 [ZJOI2012]网络
    Luogu 2147 洞穴勘测
  • 原文地址:https://www.cnblogs.com/jiangguang/p/13724861.html
Copyright © 2011-2022 走看看