vb.net - Putting multiple labels in a second form -
hi day guys ask if code putting multiple labels in second form text first form using 1 button? in advance , happy coding all.
private sub button3_click(byval sender system.object, byval e system.eventargs) handles button3.click dim lbl label = new label 'create label 'change location.. lbl.location = new point(50, 50) 'set label location lbl.text = textbox1.text 'set label text lbl.forecolor = color.black 'set label forecolor frm2.controls.add(lbl) 'add label return 'change location.. lbl.location = new point(10, 20) 'set label location lbl.text = textbox1.text 'set label text lbl.forecolor = color.black 'set label forecolor frm2.controls.add(lbl) 'add label return end sub
it shows first label not show next labels input...
form2 codes
public class form2 public lbl new label private sub form2_load(byval sender system.object, byval e system.eventargs) handles mybase.load me.controls.add(lbl) end sub
end class
problem solved..many sir plutonix , steve appreciate :) accepted suggestion of plutonix use multiple textboxes rather 1 textbox , used sample code of steve in starting project.. many again :)
you need declare global class level variable keeps reference form2, when click button , global class level variable nothing (first time creation) create form2 instance, add labels , important add event handler called when frm2 instance closed. show form , bring forefront.
if user reclicks on button, new form not created (frm2 not nothing @ point), instead, if user closes frm2 event handler called , reset internal class level variable nothing. if user clicks again on button frm2 recreated
private frm2 form2 private sub button3_click(byval sender system.object, byval e system.eventargs) handles button3.click if frm2 nothing frm2 = new form2 addhandler frm2.formclosed, addressof me.form2hasbeenclosed dim lbl label = new label lbl.location = new point(50, 50) lbl.text = "firstlabeltext" lbl.forecolor = color.black frm2.controls.add(lbl) dim lbl2 = new label lbl2.location = new point(10, 20) lbl2.text = "textforsecondlabel" lbl2.forecolor = color.black frm2.controls.add(lbl2) end if frm2.show() frm2.bringtofront end sub sub form2hasbeenclosed(sender object, e formclosedeventargs) frm2 = nothing end sub private sub button2_click(byval sender system.object, byval e system.eventargs) handles button2.click if frm2 isnot nothing frm2.show(me) 'show second form end if end sub
Comments
Post a Comment