c# - Hiding a form and showing another when a button is clicked in a Windows Forms application -
i doing application windows form application. @ first, form appears, , after user hits next button, form should hidden , form shown.
i tried it. managed hide current form, next 1 won't show.
here attempt:
this button's event handler
private void button1_click_1(object sender, eventargs e) { if (richtextbox1.text != null) { this.visible=false; } else messagebox.show("insert attributes first !"); } this main function:
static void main() { application.enablevisualstyles(); application.setcompatibletextrenderingdefault(false); form2 form2 = new form2(); form1 form1 = new form1(); form2.hide(); application.run(form1); while (true) { if (form1.visible == false) form2.show(); } }
the while statement not execute until after form1 closed - outside main message loop.
remove , change first bit of code to:
private void button1_click_1(object sender, eventargs e) { if (richtextbox1.text != null) { this.visible=false; form2 form2 = new form2(); form2.show(); } else messagebox.show("insert attributes first !"); } this not best way achieve looking though. instead consider wizard design pattern.
alternatively implement custom applicationcontext handles lifetime of both forms. example implement splash screen here, should set on right path.
http://www.codeproject.com/kb/cs/applicationcontextsplash.aspx?display=print
Comments
Post a Comment