Move one form to another winforms - C#

Karthick picture Karthick · Sep 23, 2009 · Viewed 41.1k times · Source

I have 2 winforms Form 1 and Form 2. I have button1 in form1, when i click on button1 from form1 i display form2.

            Form2 ins = new Form2();
            ins.MdiParent = this.MdiParent;
            this.Hide();
            ins.ShowDialog();

I hide the form1 to display form2 when button1 is clicked. This creates a flicking effect and i need to remove this flicking. How do i open/redirect to another form (i am supposed to show only one form at a time and am not supposed to show any top menu like (if i use MDIParent form). Just one active form.

Thanks, Karthick

Answer

Matt Hamilton picture Matt Hamilton · Sep 23, 2009

It sounds a bit like you're trying to create a web-style UI where the user steps from one "page" (represented by a Form) to another.

Rather than implementing a UI like this with separate forms, you're better off doing it with UserControls hosted on a single parent form.

Have a read of this MSDN article, which includes a download with sample code. It's a great walkthrough for designing that kind of user interface:

IUIs and Web-Style Navigation in Windows Forms, Part 1

IUIs and Web-Style Navigation in Windows Forms, Part 2

Edit

If you're intent on showing two separate forms, is there any reason you need to show the second one modally? Can you not simply show it and then hide the original?

form2.Show();
form1.Hide();

... or do you have yet another form that both form1 and form2 are "modal" to?