c# - Event not firing for dynamically created Label -


i have windows form labels , created common click event handler labels. event bound code. need create more labels in run-time , bind same event handler dynamically created labels. tried following didn't work.

private void ctrl_click(object sender, eventargs e) {     control control = (control)sender;     if (control label)     {         label lbl = (label)sender;         txtcaption.text = lbl.text;         cbofont.text = lbl.font.fontfamily.name;         txtsize.text = lbl.font.size.tostring();         chkbold.checked = lbl.font.bold;         txtx.text = lbl.location.x.tostring();         txty.text = lbl.location.y.tostring();         txtwidth.text = lbl.width.tostring();         gblogo.visible = false;         gbcontrol.visible = true;         gbdetail.visible = false;     } }  private void btnadddynamic_click(object sender, eventargs e) {     label label = new label();     int count = pl.controls.oftype<label>().tolist().count;     label.location = new point(50, (25 * count) + 2);     label.autosize = true;     graphics g = label.creategraphics();     label.width =convert.toint32(g.measurestring(label.text, label.font).width);     label.name = "label_" + (count + 1);     label.text = "label " + (count + 1);     label.tabindex=0;     label.click += new eventhandler(this.ctrl_click);     pl.controls.add(label); } 


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -