Click here to Skip to main content
15,613,873 members
Please Sign up or sign in to vote.
3.33/5 (3 votes)
See more:
Please how do I move from one form to another? For example I click on the button and another form immediately show.
I know the only way and thats hiding one and showing another but it looks bad because it flickers (for very short time but still). Is there some way to do it without hiding?
Code what I use now to to that:

Form2 secondtform = new Form2();

but this cause disappearing icon showing another etc.. So I hoped there is some way to make this look like you are moving across normal windows program.

EDIT: Just tried this code to get rid of flickering
public void EnableDoubleBuffering()
   this.SetStyle(ControlStyles.DoubleBuffer |
      ControlStyles.UserPaint |

Unfortenately it doesn't solved it..
Updated 16-Aug-21 19:52pm
Shahin Khorshidnia 15-Feb-12 19:04pm    
Please Tag your question.
What kind of application are you working on? Windows, Web, WPF ...?
LosEagle 15-Feb-12 19:09pm    
I tagged it as C# do I have to add another tag? I'm working on Windows Form application :)
Sergey Alexandrovich Kryukov 15-Feb-12 20:03pm    
Yes, yes, add "Forms". This is important to have experts looking at right questions, before they load this page.
R. Giskard Reventlov 15-Feb-12 19:17pm    
Do you really need to hide the parent form? Can't you just display the child as Modal?
LosEagle 15-Feb-12 19:19pm    
Don't know how to do it :D. Will it work if I use it for more than just two forms? Sorry for noob question just learning it for few weeks :)


Try this:

private Form2 form2;
public Form1()

    this.form2 = new Form2();

private void ShowButton_Click(object sender, EventArgs e)

private int height;
private int width;
private System.Windows.Forms.FormBorderStyle borderStyle;

private void ShowForm(Form form)
    form.Visible = true;
    form.FormBorderStyle = borderStyle;
    form.Height = height;
    form.Width = width;

private void HideForm(Form form)
    height = form.Height;
    width = form.Width;
    borderStyle = form.FormBorderStyle;

    form.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
    form.Height = 0;
    form.Width = 0;
    form.Visible = false;
Share this answer
LosEagle 16-Feb-12 6:54am    
Thats similar to what I have right now but when I use hiding it looks bad when I'am "moving across program" because icon disapears and new shows etc... . But thanks for your help I appreciate that
Shahin Khorshidnia 16-Feb-12 8:29am    
You're welcome.
Normally, you don't need anything else but Form.Show, Form.Activate or Form.BringToFront please see:[^].

If this flickers, most likely you did something wrong. It's hard to say what, without having some code sample to manifest the problem. Just in case: look at my recent anti-clicker advice: Question about change form to full screen mode but my form flashing[^].

Share this answer
LosEagle 16-Feb-12 6:51am    
Thanks I will give a look :)
My code:
Form2 secondtform = new Form2();
but it doesn't look good because when moving from one form to second etc.. icon disapears new shows .. it just doesn't look normal
Sergey Alexandrovich Kryukov 17-Feb-12 21:52pm    
There is nothing particularly wrong with this particular piece of code. Maybe this is not a real flicker, just an unpleasant effect of form change.

Let's assume you patten is just showing one form at a time navigating from one to another. If so, this is just wrong UI design, technically correct, but transition effect just cannot be done smother (you can only put Hide at the and, makes the last statement instead of first).

If this is so, I could advice your a very different implementation pattern which would be nearly 100% smooth.

What you have as different forms should be refactored to become separate panels, with all the controls and layout exactly the same as in your present forms.

Now, have only one forms filled (Dock = DockStyle.Fill) with set of panels. Each panel except one should be hidden (Visisible = false), only on panel at a time is visible. The transition will be changing from one visible panel to another. You will be surprised to see how much better it will look, easier to program and support, too.

Good luck,
gggustafson 13-Oct-21 14:36pm    
LosEagle 19-Feb-12 19:53pm    
That sounds finaly like solution for my problem :) please can you give me a piece of code where you use this? I've tried to make it but I just don't know how and where to do this.
protected override CreateParams CreateParams
             const int WS_EX_COMPOSITED = 0x02000000;
             var cp = base.CreateParams;
             cp.ExStyle |= WS_EX_COMPOSITED;
             return cp;
Share this answer
Richard Deeming 17-Aug-21 4:26am    
This question was solved nearly 10 years ago. And that code has nothing to do with the question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900