Microsoft Communities

Welcome to WindowsClient.net | Sign in | Join

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

Windows Forms FAQs

How do controls behave with GetPreferredSize?

Control

Had AutoSize in Everett

AutoSize by default *

Shrinks in Anchor+

Implementation details

Could be Affected by...

Button

No

No

No

Forwards to ButtonBase - applies a minimum size of Button.DefaultSize, unless its a FlatStyle.System, in which case it only measures the text and tacks on space for system borders + Padding

Text, Image, Padding

ButtonBase

No

No

No

Forwards to ButtonBaseAdapter to measure the contents of the button + space of padding, taking into account Text/Image Align&Relation Text is measured to fit on one line

CheckBox

No

Set in DT only

Yes

Forwards to ButtonBase, unless it's FlatStyle.System, in which case we measure the text and tack on extra space for win32 borders, Padding, and some extra space to bump it up to UI guidelines

Font, Text, Padding

ComboBox

No

No

No

Uses the SpecifiedBounds.Width* and the PreferredHeight (height of measured text borders padding) - exact mixture depends on style of combobox

Font, Padding, Size, Bounds, Width, Height

ContainerControl

No

No

No

Subtracts the Padding from the constrainingSize, calls LayoutEngine.GetPreferredSize(constrainingSize) then adds back on its Padding.

Padding, child control layout

Control

No

No

No

returns SpecifiedBounds.Size*

changes to Size, Bounds, Width, Height

DateTimePicker

No

No

No

Uses the SpecifiedBounds.Width* and the PreferredHeight (height of measured text borders padding)

Font, Padding

DataGridView

No

No

No

Measures column widths, row heights, tacks on room for scrollbars + padding

changes to column widths, heights, Padding

DomainUpDown

No

No

No

Uses largest string in collection as width, height depends on font + bordersm, added with Padding.Size

Text, Font, Padding

Form

No

No

No

Gets the PreferredSize from ContainerControl, if padding is empty - adds a magic 9 pixels to conform to UI guidelines

Padding, child control layout

GroupBox

No

No

No

Uses similar pattern to ContainerControl - asks layout engine

Padding, child control layout

Label

Yes

Set in DT only

Yes

Manages its own size in dock and anchor layout, tries to mush all text into one line. In other layouts, wraps at contstraining width. This can be controlled by setting MaximumSize.Width at the point you want to wrap

Font, Text, Padding

LinkLabel

Yes

Set in DT only

Yes

Forwards to Label

Font, Text, Padding

ListBox

No

No

No

uses MaxItemWidth, measures item heights in PreferredHeight, adds space for system borders and Padding

item height changes, padding, border styles

ListView

No

No

No

Padding not used

NumericUpDown

No

No

No

uses width of largest digit height of text system borders + padding

Text, Font, Padding

Panel

No

No

No

uses similar logic to ContainerControl

border styles, padding, child control layout

PictureBox

No

No

No

uses image.Size system borders Padding

changes to image, border style, padding

RadioButton

No

Set in DT only

Yes

Forwards to ButtonBase, unless it's FlatStyle.System, in which case we measure the text and tack on extra space for win32 borders, Padding, and some extra space to bump it up to UI guidelines

changes to text, padding, font

RichTextBox

No

No

No

Forwards to TextBoxBase, tacking on room for scrollbars

changes to text, font, padding, multiline, wordwrap

TextBox

No

No

No

Forwards to TextBoxBase, tacking on room for scrollbars (typically sizes height to Font height in multiline=false)

changes to text, font, padding, multiline, wordwrap

TextBoxBase

No

No

No

Measures text, adds on borders and padding

ToolStrip

No

Yes

No

Similar to ContainerControl. In SplitStack, it measures all the room for the Overflow.AsNeeded and Overflow.Never items + room for overflow & grip. In all other layouts, refer to that layout engine's behavior

changes to child element layout properties, font, padding

ToolBar

Yes

Yes

No

Manages its own size according to widths of buttons - calculates number of rows needed to display them all.

changes to button width

TrackBar

Yes

No

No

Manages its own size - scrollbar height * 8


*
Shrinks in anchor: If the control doesnt shrink by default in anchor, and the preferred size is smaller than the current size of the control, DockAndAnchorLayout will not shrink the control. In order to shrink controls like this, turn AutoSize=true and set Size=0,0


Page view counter