S saulij Oct 8, 2008 #1 I have an array of buttons. There is a common Click-method for these buttons. How can I find what button is clicked? Sauli
I have an array of buttons. There is a common Click-method for these buttons. How can I find what button is clicked? Sauli
D Duggi Oct 8, 2008 #2 I have an array of buttons. There is a common Click-method for these buttons. How can I find what button is clicked? Sauli Click to expand... In the event handler, first arg would be "object sender". you can identify the sender through this argument. (I believe so) -Cnu
I have an array of buttons. There is a common Click-method for these buttons. How can I find what button is clicked? Sauli Click to expand... In the event handler, first arg would be "object sender". you can identify the sender through this argument. (I believe so) -Cnu
Z zacks Oct 8, 2008 #3 In the event handler, first arg would be "object sender". you can identify the sender through this argument. (I believe so) Click to expand... I haven't tried this but it should work. Private void Common_Click(Object sender, EventArgs e) { Button btn = (Button)sender; switch (btn.Name) { case "btnButton1": Do something for button1; break; case "btnButton2": Do something for button2; break; etc ... } }
In the event handler, first arg would be "object sender". you can identify the sender through this argument. (I believe so) Click to expand... I haven't tried this but it should work. Private void Common_Click(Object sender, EventArgs e) { Button btn = (Button)sender; switch (btn.Name) { case "btnButton1": Do something for button1; break; case "btnButton2": Do something for button2; break; etc ... } }
D Duggi Oct 8, 2008 #4 I haven't tried this but it should work. Private void Common_Click(Object sender, EventArgs e) { Button btn = (Button)sender; switch (btn.Name) { case "btnButton1": Do something for button1; break; case "btnButton2": Do something for button2; break; etc ... } }- Hide quoted text - - Show quoted text - Click to expand... nice to see some code here. The same approach I was suggesting. Saulij, Please let us know if it solves your issue. -Cnu
I haven't tried this but it should work. Private void Common_Click(Object sender, EventArgs e) { Button btn = (Button)sender; switch (btn.Name) { case "btnButton1": Do something for button1; break; case "btnButton2": Do something for button2; break; etc ... } }- Hide quoted text - - Show quoted text - Click to expand... nice to see some code here. The same approach I was suggesting. Saulij, Please let us know if it solves your issue. -Cnu
A Arthur Parker Oct 8, 2008 #5 Also, you could set the Tag property for each button and use that to identify them.
S saulij Oct 13, 2008 #6 Duggi kirjoitti: nice to see some code here. The same approach I was suggesting. Saulij, Please let us know if it solves your issue. -Cnu Click to expand... This works fine, Thanks a lot sauli
Duggi kirjoitti: nice to see some code here. The same approach I was suggesting. Saulij, Please let us know if it solves your issue. -Cnu Click to expand... This works fine, Thanks a lot sauli