Based on this question I am trying to do the same thing for the TextBox Leave event. This should have been a no-brainer and I created an extension method as follows:
public static class TextBoxExtensions
{
public static bool IsLeaveEventWired(this TextBox txt)
{
var eventKey = typeof(TextBox).GetField("EVENT_LEAVE",
System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Static)
.GetValue(txt);
EventHandlerList eventList = typeof(TextBox).GetProperty("Events",
System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Instance)
.GetValue(txt, null) as EventHandlerList;
return eventList[eventKey] != null;
}
}
The problem is that apparently the EVENT_LEAVE key does not exist because I am getting a NullReferenceException. So far I have tried getting all the TextBox's fields but I only get one FieldInfo object "EVENT_TEXTALIGNCHANGED" which is not an event that I have a handler for and the two events that I do, "Leave" and "KeyUp" are not included in the list.
So as the title of the question, how can I find the key to the TextBox's Leave event to see if it is wired or not?
Thank you.