Back to Devexpress

LabelControl.Text Property

windowsforms-devexpress-dot-xtraeditors-dot-labelcontrol-33aabbb3.md

latest9.1 KB
Original Source

LabelControl.Text Property

Gets or sets the label’s text.

Namespace : DevExpress.XtraEditors

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DefaultValue("")]
[DXCategory("Appearance")]
[SettingsBindable(true)]
public override string Text { get; set; }
vb
<DXCategory("Appearance")>
<SettingsBindable(True)>
<DefaultValue("")>
Public Overrides Property Text As String

Property Value

TypeDefaultDescription
StringString.Empty

A String value that specifies the label’s text.

|

Remarks

If the LabelControl.AllowHtmlString property is set to true , you can use HTML tags to format the Text. For detailed information, see HTML Text Formatting.

Note

Long words are not wrapped if the Text option is enabled.

Example

The following example shows how to format a LabelControl‘s text using HTML tags. HTML formatting is enabled with the LabelControl.AllowHtmlString property. To respond to end-user clicks on a hyperlink, the LabelControl.HyperlinkClick event is handled. The image below shows the result:

csharp
labelControl1.Text = "<size=14>Size = 14
" +
                     "<b>Bold</b> <i>Italic</i> <u>Underline</u>
" + 
                     "<size=11>Size = 11
" + 
                     "<color=255, 0, 0>Sample Text</color></size>" +
                     "<href=www.devexpress.com>Hyperlink</href>";
labelControl1.AllowHtmlString = true;
labelControl1.Appearance.TextOptions.WordWrap = DevExpress.Utils.WordWrap.Wrap;
labelControl1.Appearance.Options.UseTextOptions = true;
labelControl1.AutoSizeMode = DevExpress.XtraEditors.LabelAutoSizeMode.Vertical;
labelControl1.HyperlinkClick += LabelControl1_HyperlinkClick;

private void labelControl1_HyperlinkClick(object sender, DevExpress.Utils.HyperlinkClickEventArgs e) {
    System.Diagnostics.Process.Start(e.Link);
}
vb
labelControl1.Text = "<size=14>Size = 14
" + _
                     "<b>Bold</b> <i>Italic</i> <u>Underline</u>
" + _
                     "<size=11>Size = 11
" + _
                     "<color=255, 0, 0>Sample Text</color></size>
" + _
                     "<href=www.devexpress.com>Hyperlink</href>"
labelControl1.AllowHtmlString = True
labelControl1.Appearance.TextOptions.WordWrap = DevExpress.Utils.WordWrap.Wrap
labelControl1.Appearance.Options.UseTextOptions = True
labelControl1.AutoSizeMode = DevExpress.XtraEditors.LabelAutoSizeMode.Vertical
labelControl1.HyperlinkClick += LabelControl1_HyperlinkClick

Private Sub LabelControl1_HyperlinkClick(sender As Object, e As DevExpress.Utils.HyperlinkClickEventArgs) Handles LabelControl1.HyperlinkClick
    System.Diagnostics.Process.Start(e.Link)
End Sub

The following code snippets (auto-collected from DevExpress Examples) contain references to the Text 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/EventToCommandBehaviorParametersConverters/PassingParametersToCommandsUserControl.cs#L23

csharp
LabelControl label = new LabelControl();
label.Text = "Click to Execute Command";
label.Dock = DockStyle.Fill;

winforms-dashboard-async-mode-designer-data-loading/CS/DashboardDesignerAsyncModeExample/Form1.cs#L35

csharp
dashboardDesigner1.AsyncMode = true;
lblMode.Text = "ASYNC";
dashboardDesigner1.LoadDashboard("test.xml");

xaf-how-to-create-information-panels/CS/EFCore/InfoPanelEF/InfoPanelEF.Win/XafSplashScreen.cs#L38

csharp
LoadBlankLogo();
this.labelCopyright.Text = "Copyright © " + DateTime.Now.Year.ToString() + " Company Name" + System.Environment.NewLine + "All rights reserved.";
UpdateLabelsPosition();

xaf-how-to-extend-the-application-model/CS/EFCore/ExtendModelEF/ExtendModelEF.Win/XafSplashScreen.cs#L38

csharp
LoadBlankLogo();
this.labelCopyright.Text = "Copyright © " + DateTime.Now.Year.ToString() + " Company Name" + System.Environment.NewLine + "All rights reserved.";
UpdateLabelsPosition();

XAF_Non-Persistent-Objects-Filtering-Demo/CS/EFCore/NonPersistentFilteringEF.Win/XafSplashScreen.cs#L38

csharp
LoadBlankLogo();
this.labelCopyright.Text = "Copyright © " + DateTime.Now.Year.ToString() + " Company Name" + System.Environment.NewLine + "All rights reserved.";
UpdateLabelsPosition();

winforms-mvvm-best-practices/VB/EventToCommandBehaviorParametersConverters/PassingParametersToCommandsUserControl.vb#L23

vb
Dim label As New LabelControl()
label.Text = "Click to Execute Command"
label.Dock = DockStyle.Fill

winforms-dashboard-async-mode-designer-data-loading/VB/DashboardDesignerAsyncModeExample/Form1.vb#L35

vb
dashboardDesigner1.AsyncMode = True
lblMode.Text = "ASYNC"
dashboardDesigner1.LoadDashboard("test.xml")

XPO_how-to-filter-a-collection-by-an-associated-objects-properties-e886/VB/Form1.vb#L295

vb
If ReferenceEquals(criteria, Nothing) Then
    labelControl1.Text = String.Empty
Else

winforms-scheduler-customize-appointment-flyout/VB/CustomAppointmentFlyoutExample/MyFlyout.vb#L16

vb
InitializeComponent()
labelControl1.Text = subject
labelControl2.Text = start.ToString()

winforms-save-restore-active-skin-palette/VB/DXApplication1/Form1.vb#L56

vb
Private Sub ShowSettings()
    labelControl1.Text = Settings.Default.SkinName
    labelControl4.Text = If(Not Equals(Settings.Default.Palette, String.Empty), Settings.Default.Palette, "n/a (default palette or raster skin)")

See Also

AllowHtmlString

HTML-inspired Text Formatting

IndentBetweenImageAndText

PlainText

LabelControl Class

LabelControl Members

DevExpress.XtraEditors Namespace