tags:

views:

2019

answers:

7

Hi,

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

+1  A: 

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?

Matt Hamilton
Thanks Matt. I have more forms but at one instant only one form should be visible.
A: 

Thanks Matt. I am not trying to create web styled step mannered U.I. I need to show only one form at a time active.

When i do that from Form1 to Form2

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

creates a flicking as the screen disappears, Can you suggest some alternative ?

Please help me.

A: 

Sorry..

ins.ShowDialog();
this.Hide();

This is not hiding the previous window and new window is opened. I need to have only one window on the task bar.

Please suggest.

No i don't want to include the property to show or not to show in task bar.

  1. Create a form1
  2. Put a button and redirect to form2
  3. I need to do without flicking and also only one form should be opened and available
@Karthick - update your question or leave comments rather than posting answers.
Matt Hamilton
Ok thanks and sorry about that. Please tell me what can be the best source code for that...Am struggling with a simple step here.
A: 

I think there is a property on winforms if you would like to show it on the task bar or not.

mcxiand
A: 

Hi Matt,

Sorry I couldn't find the add comment link. Please excuse.

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

When i implement this it works, but since i have many forms this concept leads me to system out of memory exception as i keep hiding forms one after another.

How do i release form once its hidden?

Please reply.

A: 

Instead of hide use close option.

Form1 formObject = new Form1(); formObject.Close();

or simply this.Close();

Abhishek
A: 

I can clarify your doubt about how to redirect from one form1 to form2

for example: place a link in form1 and then write following code in it

form2 ins=new form2();
ins.show();
vishnu