2
votes

Context:

I'm trying to build a form using Microsoft Prism guidelines.

I have two user controls that get injected into a form. The form contains two panels that represent the containers which will hold the user controls.

The user controls get inject at run time via DI (I'm using the MVP pattern which is similar to MVVM but tweaked for Winforms).

The form has a default minimum size but the maximum size was not specified. The only way to resize the form is to make it fullscreen. It has the AutoSize property set to TRUE and the AutoSizeMode set to GrowAndShrink

Both user controls have the AutoSize set to TRUE. All the containers inside the user controls have the AutoSize property set to TRUE, DOCK set to FILL and AutoSizeMode=GrowAndShrink. The maximum size for a control is not set.

The panels inside the the form are stacked one under another and have the Anchor property set to: TOP, LEFT,RIGHT, respectively: BOTTOM, LEFT, RIGHT.

Problem:

When resizing the form to fullscreen, I would expect that the user control to expand to fill the entire screen.

That is not happening.

The user controls do not change in size and I can't figure out a reason for it.

Thanks.

UPDATE

If I change the DOCK property of the panels inside the form to TOP, respectively FILL, the panel will get resized, but the user controls inside the panels remain unchanged.

2
You are giving a bunch of conflicting layout directions, Anchor resizes, Dock resizes, AutoScale resizes, what is actually supposed to happen? If these UCs need to scale proportionally then use a TableLayoutPanel that's docked to fill. - Hans Passant
I mentioned all the layout setting because so that someone can point out some obvious mistake. The end goal is to be able to inject two custom controls in a form at run-time, dynamically, that are re-sizing properly. Any that works, and doesn't need extra code is welcomed. - Radu Cojocari

2 Answers

2
votes

Forget about setting Dock and AutoSizeMode on your controls—just use Anchor and you will find it works just fine.

I never use AutoSize = true. I always have it at false (as a matter of fact I had to check some of my forms to verify that the AutoSize and AutoSizeMode properties even existed on controls on my forms).

In the scenario you describe, I would have the Anchor set to Top, Left, Bottom, Right, both for the panels and the controls contained within.

1
votes

Set the Dock of the control in the panel also to Fill.