Converting string to Event type

string temp = fileNewMenuItem_Click;
System.EventHandler temp = new System.EventHandler(temp);

How can I do this conversion....

prgeorge3383Asked:
Who is Participating?
 
Expert1701Connect With a Mentor Commented:
This should work:

  {
    string temp = "fileNewMenuItem_Click";
    EventHandler handler = (EventHandler)Delegate.CreateDelegate(typeof(EventHandler), this, temp);

    handler(null, null);
  }

  void fileNewMenuItem_Click(object sender, EventArgs e)
  {
  }

if fileNewMenuItem_Click is a static method use,

  EventHandler handler = (EventHandler)Delegate.CreateDelegate(typeof(EventHandler), typeof(CLASS_NAME), temp);
0
 
prgeorge3383Author Commented:
cool it worked great
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.