Why doesn't SuspendLayout / ResumeLayout actually work?

J

JezB

I try to use these methods to avoid excessive repainting of the screen when
I'm changing alot of visual properties, but they don't seem to work as I
want them to.

If I use them on a Form object does it also prevent repainting of all the
form's controls as well as the Form object itself ?

Same goes for a Panel - if I use SuspendLayout on a panel and then
programatically add controls to that panel before performing a ResumeLayout
on the panel, why do all these controls seem to appear one by one?
 
H

Herfried K. Wagner [MVP]

JezB said:
I try to use these methods to avoid excessive repainting of the screen when
I'm changing alot of visual properties, but they don't seem to work as I
want them to.

If I use them on a Form object does it also prevent repainting of all the
form's controls as well as the Form object itself ?

Same goes for a Panel - if I use SuspendLayout on a panel and then
programatically add controls to that panel before performing a
ResumeLayout on the panel, why do all these controls seem to appear one by
one?

'SuspendLayout' will only disable layout logic, which includes docking and
anchoring for controls. It won't prevent them from being redrawn

Preventing controls from redrawing
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=disableredrawing&lang=en>
 
J

JezB

A-ha. How would I go about doing what I want to do ? Or is it actually worth
the effort ? I've noticed in the panel example, the controls are visibly
painted one by one (though its normally quite quick, it's still visible). I
think it would be better to have them all appear together.
 
H

Herfried K. Wagner [MVP]

JezB said:
A-ha. How would I go about doing what I want to do ? Or is it actually
worth the effort ? I've noticed in the panel example, the controls are
visibly painted one by one (though its normally quite quick, it's still
visible). I think it would be better to have them all appear together.

Disable drawing for the container, add all of the controls and enable
redrawing. Maybe this solves the problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top