I have 50 buttons in my project as all are linked, when pressed, to a method. And now, when a button has been pressed I want it to go invisible. Since I don’t want my code to contain 50 IF statements to check which
button that has been pressed:
If(sender == Button1)
{
Button1.visible = false;
}
This code gets very long if I ill have almost the same block of code when only the button name changes 50 times.
Is there anyway to this in another way to get a shorter code?
Maybe: If a String variable contains the name of the button?
string buttoncheck = Button1;
And then in the upper code insert buttoncheck instead of Button1 since buttoncheck contains the value/name of Button1?
Thanks!
Try