AutoSize Property Overview
The AutoSize property enables a control to change its size, if necessary, to attain the value specified by the PreferredSize property. You adjust the sizing behavior for specific controls by setting the AutoSizeMode property.
The AutoSize property produces somewhat different behavior, depending on the specific control type and the value of the AutoSizeMode property, if the property exists. The following table describes the behaviors that are always true and provides a brief description of each:
Always true behavior
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 its Location property always remains constant.
When a control's contents cause it to grow, the control grows toward the right and downward. Controls do not grow to the left.
The value of the control's Location property is adjusted to the correct value.
There is no minimum size set by default.
This means that if a control is set to shrink under AutoSize and it has no contents, the value of its Size property is 0,0. In this case, your control will shrink to a point, and it will not be readily visible.
This means that setting AutoSize to true will have no effect.
This size is enforced as a maximum size. This is not the case when the cell is part of an AutoSize row or column.
The AutoSizeMode property provides more fine-grained control over the default AutoSize behavior. The AutoSizeMode property specifies how a control sizes itself to its content. The content, for example, could be the text for a Button control or the child controls for a container.
The following table shows the AutoSizeMode settings and a description of the behavior each setting elicits.
The control grows or shrinks to encompass its contents.
This is the same behavior as controls with the AutoSize property and no AutoSizeMode property.
The control grows as much as necessary to encompass its contents, but it will not shrink smaller than the value specified by its Size property.
This is the default value for AutoSizeMode.
The following table lists the controls that support the AutoSize and AutoSizeMode properties.
The following table describes the sizing behavior of a control at design time, based on the value of its AutoSize and AutoSizeMode properties.
Design-time sizing gesture
The user cannot resize the control at design time, except for the following controls:
The user cannot resize the control at design time.
The user can resize the control at design time. When the Size property is set, the user can only increase the size of the control.
User can resize the control at design time.
To maximize productivity, the Windows Forms Designer shadows the AutoSize property for the Form class. At design time, the form behaves as though the AutoSize property is set to false, regardless of its actual setting. At runtime, no special accommodation is made, and the AutoSize property is applied as specified by the property setting.