How can I format multiple button in minimal OnEvent() function?

97 Views Asked by At

I have a screen with over fifty buttons on it. I want to be able to detect which button was clicked and then proceed to a different screen with data based on what button was clicked. However, I can't seem to detect a click from the mouse without the use of a specific button name. I would like to avoid using 50+ OnEvent() functions if possible. If not, I will just write them all.

Any advice would be greatly appreciated on how I can go about doing this, thanks!

1

There are 1 best solutions below

0
On

You are using C#? C++? VB.NET? Java? C# Code:

Here is an Event as Example:

    private void button1_Click(object sender, EventArgs e)
    {
        if (sender is Button)
        {
            MessageBox.Show((sender as Button).Name);
        }
    }

 

You can replace the MessageBox, it is just meant to make it a proof by example.