vb.net - How to load a form again without exiting the application? -
i have 2 form. form1 , form2. in form1 there's button go form2 if click. if click button if form1, form2 load , integer become 1. if click button in form2, integer become 0 , form1. since im in form1, if click again button in form1 go form2 form2 not load again. theres way load again form? heres example:
form1:
public class form1 private sub button1_click(sender object, e eventargs) handles button1.click me.hide() form2.show() end sub end class
form2:
public class form2 dim integer = 0 private sub form2_load(sender object, e eventargs) handles mybase.load = 1 msgbox("load complete!!") end sub private sub button1_click(sender object, e eventargs) handles button1.click = 0 me.hide() form1.show() end sub end class
thanks in advance!
form2's load method gets called once because normal life cycle form. load event gets called once before form loaded first time.
from form.load event:
occurs before form displayed first time.
the solution depends on needs. if need keep state of form when hidden want use visiblechanged event.
private sub form2_visiblechanged(sender object, e eventargs) handles me.visiblechanged if me.visible msgbox("visible changed") end if end sub
if don't need keep state can discard form 2 , recreate it:
private sub button1_click(sender object, e eventargs) handles button1.click me.hide() dim form2 = new form2() form2.show() end sub dim integer = 0 private sub form2_load(sender object, e eventargs) handles mybase.load = 1 msgbox("load complete!!") end sub private sub button1_click(sender object, e eventargs) handles button1.click = 0 form1.show() me.close() end sub
Comments
Post a Comment