日期:2014-05-17 浏览次数:20874 次
public bool HasTextChangedEvent(Control ctl, string eventName)
{
PropertyInfo propertyInfo = ctl.GetType().GetProperty("Events", BindingFlags.NonPublic
------解决方案--------------------
BindingFlags.Instance);
EventHandlerList events = propertyInfo.GetValue(ctl, null) as EventHandlerList;
FieldInfo fieldInfo = (typeof(Control)).GetField("EventText", BindingFlags.NonPublic
------解决方案--------------------
BindingFlags.Static);
Delegate del = events[fieldInfo.GetValue(null)];
if (del == null) return false;
foreach (Delegate d in del.GetInvocationList())
{
if (d.Method.Name == eventName)
return true;
}
return false;
}
MessageBox.Show(HasTextChangedEvent(textBox1, "textBox1_TextChanged").ToString());