0
votes

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;
    }
3
Without seeing your code I can only advise to to try a double-buffered panel subclass - TaW

3 Answers

1
votes

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;
0
votes

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.

0
votes
#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);