Click here to Skip to main content
12,882,639 members (36,940 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# Windows Forms
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..
Posted 15-Feb-12 12:38pm
Updated 16-Feb-12 5:07am
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 :)
mark merrens 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 :)
SAKryukov 15-Feb-12 20:03pm
Yes, yes, add "Forms". This is important to have experts looking at right questions, before they load this page.
SAKryukov 15-Feb-12 20:04pm
"Improve question". Add a tag.
SAKryukov 15-Feb-12 20:36pm
I basically answered, but please understand that you did not provide enough information to pin-point the reason of flicker.

So, if my advice cannot help your with flicker, this is not my fault; you would need to demonstrate such flicker on a code sample.
LosEagle 16-Feb-12 6:45am
The reason of flickering is because I use this
Form2 secondtform = new Form2();
So it hides first form and shows second.
I'am going to try your solution :)
Rate this: bad
Please Sign up or sign in to vote.

Solution 1


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;
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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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[^].

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
SAKryukov 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,
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.

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170422.1 | Last Updated 16 Feb 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100