Search code examples
c#visual-studioflickertablelayoutpanel

TablelayoutPanel Slow Redraw


I have 3 Tablelayouts as nested in my Form, The problem I am facing is the slow redraw when I maximize or minimize the form, I read about the Double Buffered property and found questions regarding double buffer of Tablelayoutpanel, but I don't know How to create subclass of tablelayoutpanel in visual studio and how to add subclass in toolbox?


Solution

  • For the use of CreateParams. It is called automatically when the form is drawn, so there is no need to explicitly call it. You should be able to modify the form's CreateParams property directly.

    public Form1()
    {
        InitializeComponent();
    }
    
    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams cp = base.CreateParams;
            cp.ExStyle |= 0x02000000; // WS_EX_COMPOSITED
            return cp;
        }
    }
    

    I'm not sure how long your delay is.

    Likely the main cause of the problem is your multiple levels of nesting. You may need to modify how your controls are laid out.

    There is another method you can try:

    private void Form1_Resize(object sender, System.EventArgs e)
    {
        if (WindowState == FormWindowState.Minimized)
        {
            tableLayoutPanel1.SuspendLayout();
        }
        else if (WindowState == FormWindowState.Normal || WindowState == FormWindowState.Maximized)
        {
            tableLayoutPanel1.ResumeLayout(true);
        }
    }