I have 4 buttons and I have linked everyone to the same method in the code.
Now i wanna check which button that has been pressed, by using the code:
if(sender == button1)
{
//something
}
It seems like sender gives the text of the button that has been pressed, i would like the sender to give the name of the button!
Thanks!
Usually you do not have to check the sender of an event handler because it is assumed that your senders have unique meaninga and therefore unique event handlers. If you’re tempted to shove all functionality in one event handler it’s a bad practice. You will end up with code that is not maintainable.
However, every rule has exceptions, and in some cases it makes sense to reuse an event handler for multiple senders. In this case you can either cast or use is/as operators to identify the sender: