I'm creating a windows form application with an awfull lot of buttons. 81 to be precise.
I have set an event on all these buttons to one function: changeButtonToTextbox(object sender, MouseEventArgs e)
This works fine, but the program needs to know which button really is clicked.
I can do this with a simple if(sender == button1). But I don't feel like making a switch statement with 81 possibilities.
It wouldn't be efficient too.
Suppose I want to change one property of a button; visibility. How would I do this
How can I determine which button is clicked and respond on that by making the button invisible
TiA,
MaximusBrood

Catching multiple buttons in one function
Amit Nalla
private void button1_Click(object sender, EventArgs e)
{
((Button)sender).Visible = false;
}
KentDy
Hi,
Button b = (Button) sender;
b.visible = false;
please take care of possible typo mistakes I did not test this in visual studio.
The idea is that you get an object reference to the pressed button via sender. So you actually can cast this into a button object and use it's properties and methods, without actually knowing the name of the pressed button.
GuruprasadTG
I've tested and it works perfectly
MaximusBrood