How to pass a parameter in an event
-
Hi.. i'm making a program and this is how it goes.. I have actually two buttons and having the same event handler... how will i know which button triggered the event?.. what i was planning to do is just to pass a parameter to the method but it seems like the only parameters that is only allowed is the (object sender, EventArgs e)... am not that really proficient in C# so i guess you could give me solutions and workarounds on how to do this
-
Hi.. i'm making a program and this is how it goes.. I have actually two buttons and having the same event handler... how will i know which button triggered the event?.. what i was planning to do is just to pass a parameter to the method but it seems like the only parameters that is only allowed is the (object sender, EventArgs e)... am not that really proficient in C# so i guess you could give me solutions and workarounds on how to do this
The object 'sender' is the button that triggered the event. just cast it to button type and check if it is the one you require. e.g. Button b = sender as Button; if(b == button1) .....; else ...; or you could assign a value in the "Tag" property of the button and check it in the event handler.
regards :)
-
The object 'sender' is the button that triggered the event. just cast it to button type and check if it is the one you require. e.g. Button b = sender as Button; if(b == button1) .....; else ...; or you could assign a value in the "Tag" property of the button and check it in the event handler.
regards :)
-
Thanks a lot.. can i also cast like using the java syntax like "Button b = (Button) sender" <--- is that possible?