Microsoft Communities

Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

What are some AutoSize considerations with LayoutEngines?

The LayoutEngine iterates through all child controls and asks each control for its preferred size via GetPreferredSize when AutoSize = true. Each layout engine is free to do what it wants with this information.

Dock layout

  • Left, Right - controls size to PreferredSize.Width, stretch to fill height
  • Top, Bottom - controls size to PreferredSize.Hidth, strech to fill width
  • Fill - controls stretch to fit remaining space, do not use preferred size

Anchor layout

Controls generally size to their preferred size, constrained by their anchors. By default, controls in AnchorLayout do not shrink below their specified size, that is turning on AutoSize should not shrink a control - rather it can only make it grow. The controls that are the exception to this rule are CheckBox and RadioButton. In later versions, we plan on adding a ControlStyle switch to let this be more configurable.

FlowLayout

Controls are generally set to their preferred size, except in the case that they have a Dock or Anchor property set to Align or Fill them to a row.

TableLayout

Controls are generally set to their preferred size, if there isn't enough width in a column, it asks the control to grow in height if it can.

All of the LayoutEngines try their best to set the size to the PreferredSize, however this can be limited by MinimumSize and MaximumSize. These set the absolute upper and lower bounds for control sizing.



Page view counter