Back to Devexpress

LabelControl.AutoSizeMode Property

windowsforms-devexpress-dot-xtraeditors-dot-labelcontrol-5c39c5f3.md

latest5.5 KB
Original Source

LabelControl.AutoSizeMode Property

Gets or sets the direction in which the label grows to display its entire contents.

Namespace : DevExpress.XtraEditors

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DefaultValue(LabelAutoSizeMode.Default)]
[DXCategory("Layout")]
public LabelAutoSizeMode AutoSizeMode { get; set; }
vb
<DefaultValue(LabelAutoSizeMode.Default)>
<DXCategory("Layout")>
Public Property AutoSizeMode As LabelAutoSizeMode

Property Value

TypeDefaultDescription
LabelAutoSizeModeDefault

The direction in which the label grows to display its entire contents.

|

Available values:

NameDescription
Default

In Visual Studio 2002 and 2003, the same as the None option.

In Visual Studio 2005 and more recent versions, the same as the Horizontal option.

| | None |

Disables the auto size mode. An end-user is allowed to change both the label’s width and height.

| | Horizontal |

The label is automatically resized to display its entire contents horizontally. The label’s size depends only on the length of the text and the font settings, the label cannot be resized by an end-user.

| | Vertical |

The label’s height is automatically changed to display its entire contents. In this instance, an end-user can change the label’s width while its height is automatically adjusted to fit the label’s text.

|

Remarks

If the AutoSizeMode property is set to LabelAutoSizeMode.Horizontal, the label automatically changes its width to display its entire contents. Its size depends only on the length of the text and on the font settings, the label cannot be resized by a user.

If the AutoSizeMode property is set to the LabelAutoSizeMode.Vertical value, the label automatically changes its height to display its entire contents. In this instance, a user can change the label’s width while its height automatically adjusts to fit the label’s text.

The code sample below illustrates a label control that grows horizontally until 300 pixels, after which it wraps the text to next line(s).

csharp
int nMaxWidth = 300;

labelControl1.AutoSizeMode = LabelAutoSizeMode.Vertical;
labelControl1.Width = nMaxWidth;
labelControl1.Text = "This is an example of a label control that stretches vertically to hold a long text.";
vb
Dim nMaxWidth As Integer = 300

labelControl1.AutoSizeMode = LabelAutoSizeMode.Vertical
labelControl1.Width = nMaxWidth
labelControl1.Text = "This is an example of a label control that stretches vertically to hold a long text."

The following code snippets (auto-collected from DevExpress Examples) contain references to the AutoSizeMode property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-mvvm-best-practices/CS/UITriggers/SimpleUITriggerUserControl.cs#L23

csharp
label.Dock = DockStyle.Top;
label.AutoSizeMode = LabelAutoSizeMode.Vertical;
label.Text = "Inactive";

winforms-dashboard-get-underlying-data-for-clicked-item/CS/Dashboard_UnderlyingDataWin/Form1.cs#L31

csharp
};
lbl.AutoSizeMode = LabelAutoSizeMode.None;
lbl.Appearance.TextOptions.HAlignment = HorzAlignment.Center;

winforms-mvvm-best-practices/VB/UITriggers/SimpleUITriggerUserControl.vb#L23

vb
label.Dock = DockStyle.Top
label.AutoSizeMode = LabelAutoSizeMode.Vertical
label.Text = "Inactive"

winforms-dashboard-get-underlying-data-for-clicked-item/VB/Dashboard_UnderlyingDataWin/Form1.vb#L24

vb
Dim lbl As LabelControl = New LabelControl With {.Text = "No Data", .Parent = form}
lbl.AutoSizeMode = LabelAutoSizeMode.None
lbl.Appearance.TextOptions.HAlignment = HorzAlignment.Center

See Also

LabelControl Class

LabelControl Members

DevExpress.XtraEditors Namespace