简体   繁体   中英

Winforms: Resizing user controls in form control

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.

将面板中控件的Dock也设置为Fill

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM