Set button handle in C# -


        btnname1 = new button();         counter++;         //start setting of button         btnname1.location = new point(47, 35 + a);         btnname1.size = new size(132, 59);         btnname1.flatstyle = flatstyle.popup;         btnname1.text = textbox1.text;         btnname1.name = "btn" + counter.tostring();         btnname1.backcolor = color.white;         btnname1.forecolor = color.black;         panel1.controls.add(btnname1);         += btnname1.size.height + 2;         btnname1.click += btnname1_click; 

i wrote code making new button. when click on add button code runs , each click on add button can make new button. problem how can set click handle each button? mean when click on each button, show text me , wrote code make texts different:

btnname1.text = textbox1.text;

you didn't post event code, steve mentioned in comment (that appears have since been removed), can use sender argument particular button clicked. following should you're after:

private void btnname1_click(object sender, eventargs e) {     //access text with: (sender button).text      //example: write button's text debug output window     debug.writeline((sender button).text); }   

just careful in specific example, you're subscribing button event.


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -