How do I hook a custom function, so that on label click, the same function would run and pass the parameters?
List<int> _list1 = new List<int>(); //1, 2, 3, 4, 5
foreach (var item in _list1)
{
Label lb = new Label { Text = item.ToString() };
lb.Click += //custom function and pass the parameter item
}
private void CustomFunctionOnClick(int s)
{
textBox1.Text = s.ToString();
}
-> I can’t hook delegates with the click event of label.
-> For the other way round, I could have a CustomEventArgs class that would pass the data to the event (object sender, CustomEventArgs e), and I could do run same code in the event.
But the click event delegate does not define CustomEventArgs as the parameter for the event?
Then, how is this done?
1 Answer