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?
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;
Try this code
TableLayoutPanel.GetType().GetProperty("DoubleBuffered",
System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
.SetValue(TableLayoutPanel, true, null);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With