Passing a parameter in System.EventHandler in C #

Since Google failed me in the last 5-10 minutes, I have a quick question. I want to pass the parameter value to a function that I call from the button.click event handler. Event is added using

MyButton.Click = new System.EventHandler(MyButton_click);

But I want the function to get:

private void MyButton_click(int ID)
{
...
}

How can I modify an EventHandler declaration so that it can be executed?

+5
source share
2 answers

Button.Clickdefined as is, and there is no way to change it. Nevertheless,

myButton.Click += delegate { MyButton_click(1); }

will do the job.

+13
source

you can use the CommandArgument property and then pass the sender to the event handler of type Button to get the value of CommandArgument

0
source

All Articles