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

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -