I have two tab pages hosting TableLayoutPanels that I dynamically populate with labels and textboxes. The first one gets 96 labels and 96 textboxes, and its flicker is acceptable/tolerable, so I didn't bother to add a SuspendLayout/ResumeLayout pair.
However, the second one gets 96 labels and 288 textboxes, and its painting/flickering is intolerable. IOW, 192 controls seems to be okay, but 384 is decidedly not.
I was calling SuspendLayout prior to creating the controls dynamically, and then ResumeLayout in the finally block, but removed them, and voila! Like the first tabPage/TLP, the flicker is acceptable.
Why does this addition by subtraction work?
When adding several controls to a parent control, it is recommended that you call the SuspendLayout method before initializing the controls to be added. After adding the controls to the parent control, call the ResumeLayout method. This will increase the performance of applications with many controls.
The SuspendLayout and ResumeLayout methods are used in tandem to suppress multiple Layout events while you adjust multiple attributes of the control.
You may also try the two methods, I have listed in this thread. Hope they are not too arcane:
https://stackoverflow.com/a/15020157/1307504
This methods really suspends and resumes the layout. But you should never forget to call EndControlUpdate()
.
I use this in any generically control I am creating. I tried a lot with alling suspend and resume layout. It never worked the way I thought it should.
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