invoke an event manually in c#

  • Thread starter Thread starter dennis
  • Start date Start date
D

dennis

Hello

I am trying to invoke an event from a control manually in c#.
Does anyone have any ideas.

This is what I have done so far

Control b1 = getControl("button1");
EventInfo[] eventInfos = b1.GetType().GetEvents();
EventInfo eventInfo = b1.GetType().GetEvent("Click");
eventInfo.GetRaiseMethod()

So far the method hooked up to the event has not been triggered?
Any ideas? Thanks in advance

Dennis Baffour
 
dennis said:
I am trying to invoke an event from a control manually in c#.
Does anyone have any ideas.

This is what I have done so far

Control b1 = getControl("button1");
EventInfo[] eventInfos = b1.GetType().GetEvents();
EventInfo eventInfo = b1.GetType().GetEvent("Click");
eventInfo.GetRaiseMethod()

So far the method hooked up to the event has not been triggered?
Any ideas? Thanks in advance

Just getting the raise method isn't going to invoke it - you'll need to
call Invoke on the MethodInfo returned by GetRaiseMethod().
 
Dennis,

I don't believe that this will work. Only class instances themselves
can raise events, you can not fire events outside of the class that they are
defined in.

Hope this helps.
 
Dennis,

Try this

Control b1 = getControl("button1");
if(b1 != null)
{
b1.Click += new System.EventHandler(MyClickMethod);
}

Shak.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top