Assign the same event handler to all buttons.
foreach (var button in Controls.OfType<Button>()) {
button.Click += button_Click;
}
Or you can select the same event handler in the properties window switched to events (flash icon).
private static void button_Click(object sender, EventArgs eventArgs)
{
switch (((Button)sender).Name)
{
// find a way to disambiguate.
}
}
You can also add some useful information to the Tag
property for the disambiguation. And last but not least, you can derive your own button from Button
and add appropriate properties. They will even appear in the properties window.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…