C#获取按钮的EventClick事件,EventHandlerList委托的调用列表
作者:C/S框架网|www.cscode.ne  发布日期:2021-03-20 14:29:10
  C#获取按钮的EventClick事件,EventHandlerList委托的调用列表


C# Code:

//获取按钮的Click事件
System.Reflection.PropertyInfo propertyInfo = (typeof(Control)).GetProperty("Events", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
System.Reflection.FieldInfo fieldInfo
= (typeof(Control)).GetField("EventClick", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
EventHandlerList eventHandlerList
= (EventHandlerList)propertyInfo.GetValue(Refbtn, null);
Delegate d
= eventHandlerList[fieldInfo.GetValue(null)];
if (d != null)
{
  
foreach (Delegate temp in d.GetInvocationList())//委托的调用列表
  
{
  btn.Click +
= (EventHandler)temp;
}
}

//来源:C/S框架网 | www.csframework.com | QQ:23404761




C/S框架网|原创精神.创造价值.打造精品

扫一扫加微信
C/S框架网作者微信 C/S框架网|原创作品.质量保障.竭诚为您服务

上一篇 下一篇