查询一个控件注册的事件集合,并调用

https://blog.csdn.net/lt045508/article/details/68921433

 


            PropertyInfo propertyInfo = this.panel1.GetType().GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic);
            if (propertyInfo == null)
            { return; }
            EventHandlerList eventList = (EventHandlerList)propertyInfo.GetValue(this.panel1, null);
            FieldInfo fieldInfo = typeof(Control).GetField("EventClick", BindingFlags.Static | BindingFlags.NonPublic);
            if (fieldInfo == null)
            { return; }
            Delegate delegateInfo = eventList[fieldInfo.GetValue(this.panel1)];
            if (delegateInfo == null) { return; }
            Delegate[] delegateList = delegateInfo.GetInvocationList();

            this.Invoke(delegateList[0], this.panel1, null);
            this.Invoke(delegateList[1], this.panel1, null);

 

posted @ 2018-12-30 00:01  81  阅读(246)  评论(0编辑  收藏  举报