GetMethod/Invoke a forms Load event?

  • Thread starter Thread starter nx-2000
  • Start date Start date
N

nx-2000

I'm trying to fire a forms Load event, but I don't seem to be able to,
what am I missing?

private void FireAnotherFormsLoad(Form f)
{
MethodInfo mi = f.GetType().GetMethod("Load");
if (mi != null)
mi.Invoke(f, new object[] { });
}
 
I'm trying to fire a forms Load event,
Why?


what am I missing?

That methods aren't the same as events? To reflect on an event you use
the GetEvent method. But that will not let you raise it.


Mattias
 
You wanna fire Load event? Then create a form. Upon creation this event is
fired. This is the only natural way of triggering that event. OnLoad virtual
method is the one that fires the event that fires the event and it does a
lot of internal stuff tha I believe will make the state of the framework
unstable or at least incorrect if you call it second time. For example it
adds the form to the list of open forms. I think they don't check if the
form is already there so the system will end up with having this form twise
in the cllection. What would be the side effect of this is hard to say.

Reflecting on the form object won't help because control classes don't have
delegate fields of keeping the event handlers. They use more smarter event
registration via caching event handlers in dictionary. The dictionary is
protected and is called Events and the event handlers are registered by a
key. For the load event the key is called EVENT_LOAD and is private readonly
static filed member of the form class. The latter is all implementation
details so noone should use them and program against.
 
Back
Top