Sign up for the Button.Click event. Attach the data that you want to use in the click handler to the Tag property while you are in the creation loop.
for (int i = 0; i < line; i++) { buttomArray[i] = new Button(); buttomArray[i].Tag=i; .....
The button will be the sender in the click handler (you can overlay it), and the tag will contain your value.
Button btn=(Button)sender; int value=(int)btn.Tag;
The property tag accepts any type. Therefore, you can attach any value to it.
source share