This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can trysigning in orchanging directories.
Access to this page requires authorization. You can trychanging directories.
Control placement in Windows Forms is determined not only by the control, but also by the parent of the control. This article describes the different settings provided by controls and the different types of parent containers that affect layout.
The position a control appears on a parent is determined by the value of theLocation property relative to the top-left of the parent surface. The top-left position coordinate of a control in the parent is(x0,y0). The size of the control is determined by theSize property and represents the width and height of the control.

When a control is added to a parent that enforces automatic placement, the position and size of the control is changed. In this case, the position and size of the control might not be manually adjusted, depending on the type of parent.
TheMaximumSize andMinimumSize properties help set the minimum and maximum space a control can use.
There are two control properties that help with precise placement of controls:Margin andPadding.
TheMargin property defines the space around the control that keeps other controls a specified distance from the control's borders.
ThePadding property defines the space in the interior of a control that keeps the control's content (for example, the value of itsText property) a specified distance from the control's borders.
The following figure shows theMargin andPadding properties on a control.

The Visual Studio Designer respects these properties when you're positioning and resizing controls. Snaplines appear as guides to help you remain outside the specified margin of a control. For example, Visual Studio displays the snapline when you drag a control next to another control:

Controls can be automatically placed within their parent. Some parent containers force placement while others respect control settings that guide placement. There are two properties on a control that help automatic placement and size within a parent:Dock andAnchor.
Drawing order can affect automatic placement. The order in which a control is drawn determined by the control's index in the parent'sControls collection. This index is known as theZ-order. Each control is drawn in the reverse order they appear in the collection. Meaning, the collection is a first-in-last-drawn and last-in-first-drawn collection.
TheMinimumSize andMaximumSize properties help set the minimum and maximum space a control can use.
TheDock property sets which border of the control is aligned to the corresponding side of the parent, and how the control is resized within the parent.

When a control is docked, the container determines the space it should occupy and resizes and positions the control. The width and height of the control are still respected based on the docking style. For example, if the control is docked to the top, theHeight of the control is respected but theWidth is automatically adjusted. If a control is docked to the left, theWidth of the control is respected but theHeight is automatically adjusted.
TheLocation of the control can't be manually set as docking a control automatically sets the position.
TheZ-order of the control does affect docking. As docked controls are laid out, they use what space is available to them. For example, if a control is drawn first and docked to the top, it takes up the entire width of the container. If a next control is docked to the left, it has less vertical space available to it.

If the control'sZ-order is reversed, the control that is docked to the left now has more initial space available. The control uses the entire height of the container. The control that is docked to the top has less horizontal space available to it.

As the container grows and shrinks, the controls docked to the container are repositioned and resized to maintain their applicable positions and sizes.

If multiple controls are docked to the same side of the container, they're stacked according to theirZ-order.

Anchoring a control allows you to tie the control to one or more sides of the parent container. As the container changes in size, anchored child controls maintain their distance to the anchored side.
A control can be anchored to one or more sides, without restriction. The anchor is set with theAnchor property.

TheAutoSize property enables a control to change its size, if necessary, to fit the size specified by thePreferredSize property. You adjust the sizing behavior for specific controls by setting theAutoSizeMode property.
Only some controls support theAutoSize property. In addition, some controls that support theAutoSize property also supports theAutoSizeMode property.
| Always true behavior | Description |
|---|---|
| Automatic sizing is a run-time feature. | This means it never grows or shrinks a control and then has no further effect. |
| If a control changes size, the value of itsLocation property always remains constant. | When a control's contents cause it to grow, the control grows toward the right and downward. Controls don't grow to the left. |
TheDock andAnchor properties are honored whenAutoSize istrue. | The value of the control'sLocation property is adjusted to the correct value. TheLabel control is the exception to this rule. When you set the value of a dockedLabel control'sAutoSize property to true, theLabel control won't stretch. |
| A control'sMaximumSize andMinimumSize properties are always honored, regardless of the value of itsAutoSize property. | TheMaximumSize andMinimumSize properties aren't affected by theAutoSize property. |
| There's no minimum size set by default. | This means that if a control is set to shrink underAutoSize and it has no contents, the value of itsSize property is(0x,0y). In this case, your control shrinks to a point, and it will not be readily visible. |
| If a control doesn't implement theGetPreferredSize method, theGetPreferredSize method returns last value assigned to theSize property. | This means that settingAutoSize totrue has no effect. |
| A control in aTableLayoutPanel cell always shrinks to fit in the cell until itsMinimumSize is reached. | This size is enforced as a maximum size. This isn't the case when the cell is part of anAutoSize row or column. |
TheAutoSizeMode property provides more fine-grained control over the defaultAutoSize behavior. TheAutoSizeMode property specifies how a control sizes itself to its content. The content, for example, could be the text for aButton control or the child controls for a container.
The following list shows theAutoSizeMode values and its behavior.
The control grows or shrinks to encompass its contents.
TheMinimumSize andMaximumSize values are honored, but the current value of theSize property is ignored.
This is the same behavior as controls with theAutoSize property and noAutoSizeMode property.
The control grows as much as necessary to encompass its contents, but it will not shrink smaller than the value specified by itsSize property.
This is the default value forAutoSizeMode.
The following table describes the level of auto sizing support by control:
| Control | AutoSize supported | AutoSizeMode supported |
|---|---|---|
| Button | ✔️ | ✔️ |
| CheckedListBox | ✔️ | ✔️ |
| FlowLayoutPanel | ✔️ | ✔️ |
| Form | ✔️ | ✔️ |
| GroupBox | ✔️ | ✔️ |
| Panel | ✔️ | ✔️ |
| TableLayoutPanel | ✔️ | ✔️ |
| CheckBox | ✔️ | ❌ |
| DomainUpDown | ✔️ | ❌ |
| Label | ✔️ | ❌ |
| LinkLabel | ✔️ | ❌ |
| MaskedTextBox | ✔️ | ❌ |
| NumericUpDown | ✔️ | ❌ |
| RadioButton | ✔️ | ❌ |
| TextBox | ✔️ | ❌ |
| TrackBar | ✔️ | ❌ |
| CheckedListBox | ❌ | ❌ |
| ComboBox | ❌ | ❌ |
| DataGridView | ❌ | ❌ |
| DateTimePicker | ❌ | ❌ |
| ListBox | ❌ | ❌ |
| ListView | ❌ | ❌ |
| MaskedTextBox | ❌ | ❌ |
| MonthCalendar | ❌ | ❌ |
| ProgressBar | ❌ | ❌ |
| PropertyGrid | ❌ | ❌ |
| RichTextBox | ❌ | ❌ |
| SplitContainer | ❌ | ❌ |
| TabControl | ❌ | ❌ |
| TabPage | ❌ | ❌ |
| TreeView | ❌ | ❌ |
| WebBrowser | ❌ | ❌ |
| ScrollBar | ❌ | ❌ |
The following table describes the sizing behavior of a control at design time, based on the value of itsAutoSize andAutoSizeMode properties.
Override theSelectionRules property to determine whether a given control is in a user-resizable state. In the following table, "can't resize" meansMoveable only, "can resize" meansAllSizeable andMoveable.
AutoSize setting | AutoSizeMode setting | Behavior |
|---|---|---|
true | Property not available. | The user can't resize the control at design time, except for the following controls: -TextBox -MaskedTextBox -RichTextBox -TrackBar |
true | GrowAndShrink | The user can't resize the control at design time. |
true | GrowOnly | The user can resize the control at design time. When theSize property is set, the user can only increase the size of the control. |
false orAutoSize is hidden | Not applicable. | User can resize the control at design time. |
Note
To maximize productivity, the Windows Forms Designer in Visual Studio shadows theAutoSize property for theForm class. At design time, the form behaves as though theAutoSize property is set tofalse, regardless of its actual setting. At runtime, no special accommodation is made, and theAutoSize property is applied as specified by the property setting.
TheForm is the main object of Windows Forms. A Windows Forms application usually has a form displayed at all times. Forms contain controls and respect theLocation andSize properties of the control for manual placement. Forms also respond to theDock property for automatic placement.
Most of the time a form has grips on the edges that allow the user to resize the form. TheAnchor property of a control lets the control grow and shrink as the form is resized.
ThePanel control is similar to a form in that it simply groups controls together. It supports the same manual and automatic placement styles that a form does. For more information, see theContainer: Form section.
A panel blends in seamlessly with the parent, and it does cut off any area of a control that falls out of bounds of the panel. If a control falls outside the bounds of the panel andAutoScroll is set totrue, scroll bars appear and the user can scroll the panel.
Unlike thegroup box control, a panel doesn't have a caption and border.

The image above has a panel with theBorderStyle property set to demonstrate the bounds of the panel.
TheGroupBox control provides an identifiable grouping for other controls. Typically, you use a group box to subdivide a form by function. For example, you may have a form representing personal information and the fields related to an address would be grouped together. At design time, it's easy to move the group box around along with its contained controls.
The group box supports the same manual and automatic placement styles that a form does. For more information, see theContainer: Form section. A group box also cuts off any portion of a control that falls out of bounds of the panel.
Unlike thepanel control, a group box doesn't have the capability to scroll content and display scroll bars.

TheFlowLayoutPanel control arranges its contents in a horizontal or vertical flow direction. You can wrap the control's contents from one row to the next, or from one column to the next. Alternately, you can clip instead of wrap its contents.
You can specify the flow direction by setting the value of theFlowDirection property. TheFlowLayoutPanel control correctly reverses its flow direction in Right-to-Left (RTL) layouts. You can also specify whether theFlowLayoutPanel control's contents are wrapped or clipped by setting the value of theWrapContents property.
TheFlowLayoutPanel control automatically sizes to its contents when you set theAutoSize property totrue. It also provides aFlowBreak property to its child controls. Setting the value of theFlowBreak property totrue causes theFlowLayoutPanel control to stop laying out controls in the current flow direction and wrap to the next row or column.

The image above has twoFlowLayoutPanel controls with theBorderStyle property set to demonstrate the bounds of the control.
TheTableLayoutPanel control arranges its contents in a grid. Because the layout is done both at design time and run time, it can change dynamically as the application environment changes. This gives the controls in the panel the ability to resize proportionally, so they can respond to changes such as the parent control resizing or text length changing because of localization.
Any Windows Forms control can be a child of theTableLayoutPanel control, including other instances ofTableLayoutPanel. This allows you to construct sophisticated layouts that adapt to changes at run time.
You can also control the direction of expansion (horizontal or vertical) after theTableLayoutPanel control is full of child controls. By default, theTableLayoutPanel control expands downward by adding rows.
You can control the size and style of the rows and columns by using theRowStyles andColumnStyles properties. You can set the properties of rows or columns individually.
TheTableLayoutPanel control adds the following properties to its child controls:Cell,Column,Row,ColumnSpan, andRowSpan.

The image above has a table with theCellBorderStyle property set to demonstrate the bounds of each cell.
The Windows FormsSplitContainer control can be thought of as a composite control; it's two panels separated by a movable bar. When the mouse pointer is over the bar, the pointer changes shape to show that the bar is movable.
With theSplitContainer control, you can create complex user interfaces; often, a selection in one panel determines what objects are shown in the other panel. This arrangement is effective for displaying and browsing information. Having two panels lets you aggregate information in areas, and the bar, or "splitter," makes it easy for users to resize the panels.

The image above has a split container to create a left and right pane. The right pane contains a second split container with theOrientation set toVertical. TheBorderStyle property is set to demonstrate the bounds of each panel.
TheTabControl displays multiple tabs, like dividers in a notebook or labels in a set of folders in a filing cabinet. The tabs can contain pictures and other controls. Use the tab control to produce the kind of multiple-page dialog box that appears many places in the Windows operating system, such as the Control Panel and Display Properties. Additionally, theTabControl can be used to create property pages, which are used to set a group of related properties.
The most important property of theTabControl isTabPages, which contains the individual tabs. Each individual tab is aTabPage object.

Was this page helpful?
Need help with this topic?
Want to try using Ask Learn to clarify or guide you through this topic?
Was this page helpful?
Want to try using Ask Learn to clarify or guide you through this topic?