Resolved Should forms have Me.PerformLayout() but not UserControls

aaaron

Well-known member
Joined
Jan 23, 2011
Messages
219
Programming Experience
10+
I have many projects. Some started with VB6 long ago. Many revisions later they are now Net5.
Some started life as a Form and are now Usercotrol.
They all contain: Me.SuspendLayout() and Me.ResumeLayout(False)

Some have: Me.PerformLayout() following the Me.ResumeLayout(False)

Some do not.

I wonder if they all are as they should be so I read about them and

scanned the Interment and got many hits but no precise answer to my need.

So I created a new solution and notice that the form has Me.PerformLayout() but the UserControls does not.

I don't feel that simple examples may miss something and is not enough to modify all my code.

I'd appreciate conformation or denial :

Should forms have Me.PerformLayout() but not UserControls (or at least typically do not).

Thanks in advance!
 
Solution
I could be wrong but my first guess would be that performing layout on a control also performs layout on controls down the hierarchy, which would mean that performing layout on a form would perform layout on any user controls that form contains, thus making an explicit call to PerformLayout in the user control pointless.
Should forms have Me.PerformLayout() but not UserControls
Correct. Designer adds SuspendLayout() and Me.ResumeLayout(False) in InitializeComponent for both forms and usercontrols, for forms it finally adds Me.PerformLayout(). You could assume VS development team knows what they're doing about this, and this is how it should be.
scanned the Interment and got many hits but no precise answer to my need.
Did you read the documentation too? Just in case you want to know what these calls do?
 
Correct. Designer adds SuspendLayout() and Me.ResumeLayout(False) in InitializeComponent for both forms and usercontrols, for forms it finally adds Me.PerformLayout(). You could assume VS development team knows what they're doing about this, and this is how it should be.

Did you read the documentation too? Just in case you want to know what these calls do?
I have.

The first two are clear.

It's the last one. Seems like it makes sense for a form.

It's not clear to me if it makes sense to do it for a Usercontrol.

Or do you wait and the form will do it later?
 
It makes sense to me that the code designer generates is correct, if that is what you're asking. Do you think VS has been doing this wrong for 18 years without anyone discovering it?
 
It makes sense to me that the code designer generates is correct, if that is what you're asking. Do you think VS has been doing this wrong for 18 years without anyone discovering it?
But I have code that is both ways. I'm not sure which ones are as vs generated it and which ones I modified.

I think you saying I should take the results of my little experiment as gospel!

Which, of course, I'll have to do sans more info.

Edit: Guess I was just looking to feel more comfortable as I add Me.PerformLayout() to the forms that do not have it and delete it from the Usercontrols that do.
 
Last edited:
I changed maybe a hundred files. Surprising how many Form .Designer files did not have PerformLayout() and how name UserControl files did.

There is no apparent difference when it compiles or runs. I just like my solution files to look like they were made with the latest VS.
 
I could be wrong but my first guess would be that performing layout on a control also performs layout on controls down the hierarchy, which would mean that performing layout on a form would perform layout on any user controls that form contains, thus making an explicit call to PerformLayout in the user control pointless.
 
Solution
I could be wrong but my first guess would be that performing layout on a control also performs layout on controls down the hierarchy, which would mean that performing layout on a form would perform layout on any user controls that form contains, thus making an explicit call to PerformLayout in the user control pointless.
I changed many files and adding PerformLayout to Forms had no apparent effect. Maybe the compiler compensates?

I'm kind of waiting for the other shoe to drop.

But your "guess" sure makes sense and you stating it gives some comfort.

Thanks
 

Latest posts

Back
Top