• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 420
  • Last Modified:

Converting string to Event type

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

How can I do this conversion....

0
prgeorge3383
Asked:
prgeorge3383
1 Solution
 
Expert1701Commented:
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now