Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# equivalent to VB.NET 'Handles button1.Click, button2.Click'

In VB.NET I can do

private sub button_click(sender, e) handles Button1.Click, Button2.Click etc...
do something...
end sub

Is there a method for this in C# .NET? I have roughly 16 buttons that all call the same function, just passing the text of the button to the function. I would rather not have 16 private void button_clicks calling one function.

I am not sure how to do this though (not familiar with C# to much.)

like image 627
Jeff Avatar asked Nov 23 '11 16:11

Jeff


1 Answers

Button1.Click += button_click;
Button2.Click += button_click;
like image 119
sll Avatar answered Nov 17 '22 22:11

sll