Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is SuspendLayout/ResumeLayout worthless or am I going about it wrong?

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?

like image 855
B. Clay Shannon-B. Crow Raven Avatar asked Aug 20 '12 23:08

B. Clay Shannon-B. Crow Raven


People also ask

When to use SuspendLayout?

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.

What does SuspendLayout do?

The SuspendLayout and ResumeLayout methods are used in tandem to suppress multiple Layout events while you adjust multiple attributes of the control.


1 Answers

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.

like image 59
Patrick Avatar answered Sep 21 '22 04:09

Patrick