How to put new eventhandle on existing buttons c#? -
i want put on existing button new event handle. have 9 buttons created in form , want display each name when clicked on it, don't want put on every button message manually.
how accomplish that?
you can use sender propperty of eventhandler in order that. example uses winforms buttons:
somebuttonclicked(object sender, eventargs e) { var button = sender button; messagebox.show(button.name); }
and can add event multiple buttons i.e.:
button1.click += new system.eventhandler(somebuttonclicked); button2.click += new system.eventhandler(somebuttonclicked); button3.click += new system.eventhandler(somebuttonclicked);
Comments
Post a Comment