I\'ve been looking for an answer for about an hour on Google but I did not found exactly what I\'m looking for.
Basically, I have a static Helper class that helps pe
I think the simplest code would be this:
EventHandler myEvent = (sender, e) => MyMethod(myParameter);//my delegate
myButton.Click += myEvent;//suscribe
private void MyMethod(MyParameterType myParameter)
{
//Do something
//if only one time
myButton.Click -= myEvent;//unsuscribe
}
You should create a lambda expression that calls a method with the extra parameters:
menuItemFolder.Click += (sender, e) => YourMethod(owner, dataType);
Honest admission up front: I have not tried the code below.
I think the reason
menuItemFolder.Click += new System.EventHandler(menuItemFolder_Click(sender,e,owner,dataType));
won't work is because you are actually passing to System.EventHandler () the result of the invocation of menuItemFolder_Click () with the parameters provided. You are not passing a pointer to the function itself.
Try to write another function that implements the details of menuItemFolder_Click (). See if something like
private void menuItemFolder_Click_Helper (object sender, EventArgs e, object Owner, object DataType) {
// implement details here
}
and then call the function from within menuItemFolder_Click ().