how do I parameterize an event, in c#

c#, events

Solution

One way you could solve this, would be to wrap your event handler in a closure:

Instead of this line:

boton.Click += infoApp;

Do this:

string par = "something";

boton.Click += (sender, e) => {
  //Now call your specific method here:
  infoApp(sender, e, par);
};

Problem

i want to redefine an event, i mean, i have this: ``` boton.Click += infoApp; //i think thats similar to: boton.Click = new System.EventHandler(infoApp). ``` when button 'boton' is clicked, the function/method 'infoApp' triggers, this method its something like this: ``` private void infoApp(object sender, EventArgs e) { /* my code*/ } ``` Until here, evetithing goes well; but I NEED to send another parameter to that method: ``` boton.Click += infoApp(string par) ``` so i thought that this could work: ``` private void infoApp(object sender, EventArgs e, string par) { /*My code*/ } ``` but it doesn't. I've readen things like delegates but i don't understand; and i dont know what to do in order to solve my problem; any ideas? Thanks in advance pd: sorry by my terrible english, i'm not english speaker. Try to be simple explaining. I'm using VS2008.

Original source