I am using a TableLayoutPanel for attendance marking purposes. I have added controls (a Panel and a Label) inside of this TableLayoutPanel and created events for them. In some conditions I have cleared all of the controls and proceeded to bind the same controls in different position of TableLayoutPanel. While re-binding the controls, the TableLayoutPanel flickers and is far too slow in initializing.
Suspend the layout until you've added all your controls on.
TableLayoutPanel panel = new TabelLayoutPanel();
panel.SuspendLayout();
// add controls
panel.ResumeLayout();
Also look at using Double Buffering. You'll have to create a sub-class of the TableLayoutPanel. See an example here.
//Call this function on form load.
SetDoubleBuffered(tableLayoutPanel1);
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);
}
//Works perfectly the double buffered solution for table layout panel and no flickering happens
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