Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TableLayoutPanel extremely slow

I am using TableLayoutPanel in C# (Forms). My table is pretty big with its 33 columns and 8 rows. All cells contain Label-objects.

I have already set DoubleBuffered = true; of my TableLayoutPanel by creating a new subclass:

public class DoubleBufferedTableLayoutPanel : TableLayoutPanel
{
    public DoubleBufferedTableLayoutPanel()
    {
        DoubleBuffered = true;
    }
}

If a user presses button X, all cell-controls are deleted and other labels are loaded into the table (from an array which contains all Label objects).

DEL: this.table.Controls.Remove(this.table.GetControlFromPosition(col, row));

ADD: this.table.Controls.Add(this.labelArray[row, (col+pos)], col, row);

Everything works fine, except that the progress of deleting the controls and adding the new ones takes five to ten seconds.

Is there a way other than to set DoubleBuffered = true in order to speed up this process?

like image 828
libjup Avatar asked May 09 '26 18:05

libjup


2 Answers

Use this code to avoid the slow processing of events in C#

tableLayoutPanel1.Visible = false;
tableLayoutPanel1.Controls.Clear();
tableLayoutPanel1.SuspendLayout();

  // Processing Code

tableLayoutPanel1.ResumeLayout();
tableLayoutPanel1.Visible = true;
like image 79
ram prasad Avatar answered May 12 '26 09:05

ram prasad


Try this code

TableLayoutPanel.GetType().GetProperty("DoubleBuffered",
                System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
                .SetValue(TableLayoutPanel, true, null);
like image 21
Hanburger_Jack Avatar answered May 12 '26 10:05

Hanburger_Jack



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!