Table of Contents

Class Label

Namespace
Alternet.UI
Assembly
Alternet.UI.Common.dll

Represents a text label control.

[DefaultBindingProperty("Text")]
[ControlCategory("Common")]
public class Label : GenericControl, IBaseObjectWithAttr, IBaseObjectWithId, INotifyPropertyChanged, IDisposableObject, IBaseObject, ISupportInitialize, IFocusable, ITextProperty, IComponent, IControl, IDisposable, IWin32Window, ILayoutItem, INotifyDataErrorInfo
Inheritance
Label
Implements
Derived

Examples

Here is how to declare a Label in UIXML:

<Border>
  <Label Name="label" Text="Sample Label" Margin="8" TextChanged="Label_TextChanged"/>
</Border>

And the corresponding event handler in the code-behind:

private void Label_TextChanged(object? sender, EventArgs e)
{
    var text = label.Text == "" ? "\"\"" : label.Text;
    MessageBox.Show(text, string.Empty);
}

Also, a Label can be created from code:

var Label = new Alternet.UI.Label();

Remarks

Label controls are typically used to provide descriptive text for a control. For example, you can use a Label to add descriptive text for a TextBox control to inform the user about the type of data expected in the control. Label controls can also be used to add descriptive text to a Window to provide the user with helpful information. For example, you can add a Label to the top of a Window that provides instructions to the user on how to input data in the controls on the form. Label controls can also be used to display run time information on the status of an application. For example, you can add a Label control to a form to display the status of each file as a list of files is processed.

Examples of how a Label can look on different platforms:

Set Text property to specify the text displayed on the control. A Label, like any other Control, can be disabled by setting its Enabled property to false.

Constructors

Label()

Initializes a new instance of the Label class.

Label(Control)

Initializes a new instance of the Label class with the specified parent control.

Label(Control, IEnumerable<string>)

Initializes a new instance of the Label class with the specified parent control and text content.

Label(Control, string)

Initializes a new instance of the Label class with the specified text and parent control.

Label(IEnumerable<string>)

Initializes a new instance of the Label class with the specified text lines. This constructor allows you to create a label with multiple lines of text, which will be separated by new line characters. Also this constructor turns on word wrapping by default.

Label(string?)

Initializes a new instance of the Label class with the specified text.

Fields

DefaultMnemonicMarker

Gets or sets the mnemonic marker character. Default is '&'.

DefaultMnemonicMarkerEnabled

Gets or sets whether to show mnemonic markers in the text.

ShowDebugCorners

Gets or sets whether to show debug corners when control is painted.

Properties

BackgroundColor

Gets or sets the background color for the control.

DisabledImage

Gets or sets the disabled image that is displayed near the text.

HasImage

Gets a value indicating whether an image is associated with the current instance.

HasVisibleImage

Gets a value indicating whether this control has an image that is visible.

Image

Gets or sets the image that is displayed near the text.

ImageHorizontalAlignment

Gets or sets the horizontal alignment of the image.

ImageVerticalAlignment

Gets or sets the vertical alignment of the image.

ImageVisible

Gets or sets a value indicating whether to draw image.

IsTransparent

Gets or sets a value indicating whether the control is transparent. Default is true. When true, the control's background is not drawn, allowing the parent control's background to show through. When false, the control's background is drawn normally. In both states, the control's border is drawn if applicable.

IsVerticalText

Gets or sets a value indicating whether the text should be rendered vertically.

MaxTextWidth

Gets or sets maximal width of text in the control.

MinTextWidth

Gets or sets the minimum width of the text, in dips.

MnemonicCharIndex

Gets or sets underlined character index.

MnemonicMarker

Gets or sets the character used as the mnemonic marker.

MnemonicMarkerEnabled

Gets or sets whether to process mnemonic markers in the text. If this property is not specified (default), DefaultMnemonicMarkerEnabled is used to determine whether mnemonic markers are processed.

Padding

Gets or sets the padding inside a control.

ParentBackColor

Gets or sets whether BackgroundColor is automatically updated when parent's BackgroundColor is changed.

TextAlignment

Gets or sets alignment of the text.

TextAlignmentHorizontal

Gets or sets vertical alignment of the text.

TextAlignmentVertical

Gets or sets vertical alignment of the text.

TextFormat

Gets or sets text format.

TextPrefix

Gets or sets text prefix.

TextSuffix

Gets or sets text suffix.

WordWrap

Gets or sets whether text is word wrapped in order to fit label in the parent's client area. Default is False.

Methods

DefaultPaint(PaintEventArgs)

Default painting method of the GenericControl and its descendants.

DrawDefaultText(Graphics)

Draws text in the default style using the specified parameters.

DrawDefaultText(Graphics, RectD, Color?, Color?, Font?)

Draws text in the default style.

GetDefaultPreferredSize(SizeD, bool, Func<SizeD, SizeD>)

Default method for calculating preferred size.

GetFormattedText()

Gets formatted text with TextSuffix and TextPrefix. This method returns the text to be displayed on the label.

GetFormattedTextSize(Font?)

Calculates the size of the formatted text based on the specified font.

GetImage(VisualControlState)

Gets image for the specified control state.

GetLastUsedDrawLabelParams(bool)

Retrieves the most recently used parameters for drawing and measuring a label.

GetPreferredSize(PreferredSizeContext)

Retrieves the size of a rectangular area into which a control can be fitted, in device-independent units.

GetRightSideWidth(bool)

Calculates the width of the right side of the label, including any suffix elements.

GetWithoutMnemonicMarkers(string, out int)

Removes mnemonic markers from a string and returns the index of the mnemonic character, if present.

MakeAsLinkLabel()

Changes visual style of the control to look like LinkLabel.

OnAfterParentSizeChanged(object?, HandledEventArgs)

Called after the SizeChanged event of the Parent is raised.

OnImageChanged(EventArgs)

Called when the value of the Image property changes.

OnParentChanged(EventArgs)

Called when Parent property is changed.

OnSizeChanged(EventArgs)

Called when the SizeChanged event.

OnSystemColorsChanged(EventArgs)

Called when the SystemColorsChanged event is raised.

OnTextChanged(EventArgs)

Called when the TextChanged event is raised.

OnVisibleChanged(EventArgs)

Called when the value of the Visible property changes.

RaiseImageChanged(EventArgs)

Raises the ImageChanged event and calls OnImageChanged(EventArgs).

SetDefaultComboBoxImage(CoordAndUnit?)

Sets the default combo box image for the control.

SetImages(Image?, Image?)

Sets the images for the control.

SetSvgImage(SvgImage?, KnownButton?, CoordAndUnit?)

Sets the SVG image for the control.

UpdateDrawLabelParams(UpdateDrawLabelParamsDelegate?)

Updates the parameters used for drawing labels by invoking the specified delegate.

Events

BeforeDrawText

Occurs before the text is drawn.

ImageChanged

Occurs when the Image property changes.