winforms - C# Create Dynamic Buttons and onClick Dynamic EventHandlers -


my program creates buttons dynamically.

private void createbutton(string buttonname) {     color[] c = { color.red, color.teal, color.blue, color.whitesmoke };     transbutton = new button();    transbutton.backcolor = c[2];    transbutton.text = buttonname;    transbutton.name = buttonname + "button";    transbutton.width = 150;    transbutton.height = 150;    transbutton.font = new font("segoe ui", 13);    transbutton.forecolor = color.white;     transbutton.click += new eventhandler(transbutton_click); }  private void transbutton_click(object sender, eventargs e) {     tblist.text = transbutton.text; } 

enter image description here

what trying when user clicks on button(s) adds name of button multiline textbox such in picture above. created eventhandler cant figure out how make work dynamic buttons.

you have reference button clicked right there sender argument. so...

private void transbutton_click(object sender, eventargs e)     {        tblist.text += "\r\n" + ((button)sender).text;     } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -