skip to Main Content

I’ve created a simple program and now i’m in the stages of doing my designing. I’ve got a multiple Panels which i make visible / invisible to switch between “tabs” (EG. 1 panel for the login screen and 1 panel for the create account screen). Now i’ve made these panels invisible because i want them just as containers to be able to quickly move around controls and create buttons in.

My problem is that i’ve set my forms background image to a image i made in photoshop and whenever i switch between panels it flickers, whenever i just use a system color (white,black) this doesn’t happen.
Is there any way for me to remove the flickering?

i’ve tried :

  • Setting double buffer to true
  • protected overrideing OnPaint, CreateBackground, and Createparam

my code is extremely basic :

private void btnNewAcc_Click(object sender, EventArgs e)
    {
        PanelNewAccount.Visible = true;
        PanelLogin.Visible = false;
    }

4

Answers


  1. Chosen as BEST ANSWER

    Thanks to Patrick i've solved my problem, instead of using panels i'm using a TabControl and i assigned the same background to each tab. Just as easy to add dynamic buttons as well. Same features as panels but without the flickering.


  2. Try to setting the form property DoubleBuffered to true, in winforms the flickering usually happens because the GDI+ is trying to draw the control(s) a lot of times so DoubleBuffering you graphics should help in such cases

    form.DoubleBuffered = true;
    
    Login or Signup to reply.
  3. #region .. Double Buffered function ..
           public static void SetDoubleBuffered(System.Windows.Forms.Control c)
            {
                if (System.Windows.Forms.SystemInformation.TerminalServerSession)
                    return;
                System.Reflection.PropertyInfo aProp = typeof(System.Windows.Forms.Control).GetProperty("DoubleBuffered", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                aProp.SetValue(c, true, null);
            }
    
           #endregion
    
    
    #region .. code for Flucuring ..
    
           protected override CreateParams CreateParams
            {
                get
                {
                    CreateParams cp = base.CreateParams;
                    cp.ExStyle |= 0x02000000;
                    return cp;
                }
            }
    
            #endregion
    

    Even though i am late but if somebody else is also suffering from the same problem then this code fixed the flickering for me even though i dont know how it works.
    I found it here.
    Add the above code snippet in your program and in the contructor of your app add this line:

    SetDoubleBuffered(YourPanelName);
    
    Login or Signup to reply.
  4. protected override CreateParams CreateParams {
          get {
            CreateParams cp = base.CreateParams;
            cp.ExStyle |= 0x02000000;
            return cp;
          }
        }
    

    code copy from codeproject solved my problem.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search