How to make an EventHandler for array of buttons
-
Hello everybody. I have a problem.I'm working with VS2005 and my project is a C# windows application. I define an array of buttons but I don't know how to make EventHandler for this array; Thanks for all. t_nedelchev
-
Hello everybody. I have a problem.I'm working with VS2005 and my project is a C# windows application. I define an array of buttons but I don't know how to make EventHandler for this array; Thanks for all. t_nedelchev
for (i=0; i < ...) {
btnArr[i].Click += new System.EventHandler(NameOfYourClickHandler);
btnArr[i].Tag = i; // this is needed so that you can identify which
// button was clicked
}Then declare a function called NameOfYourClickHandler:
public void NameOfYourClickHandler(object sender, System.EventArgs e) {
// do something
MessageBox.Show(((System.Windows.Button)sender).Tag.ToString());
}Ut