I have a form which initialy sizes itself to its contents (a UserControl
placed on location 0, 0) by setting AutoSize
to true and AutoSizeMode
to GrowAndShrink
.
After initialization, I want the form to take control and turn off AutoSizing and make the UserControl Dock.Fill
.
The problem is that when turning off AutoSize
, the form regains its previous size instead of keeping its current size.
I can store the Size before turning off AutoSize, and restore it afterwards, but you still get sizing events (you could see the form flicker).
Is there any way to have a form keep its current size and not have any sizing events fired when turning off AutoSize
?
Try setting the MinimumSize property of the form before turning off the AutoSize property:
this.MinimumSize = this.Size;
this.AutoSize = false;