using System.Diagnostics.CodeAnalysis; using System.Windows.Forms; namespace LibationWinForms; public class FormattableLabel : Label { public string FormatText { get; set; } /// Text set: first non-null, non-whitespace set is also saved as [AllowNull] public override string Text { get => base.Text; set { if (string.IsNullOrWhiteSpace(FormatText) && !string.IsNullOrWhiteSpace(value)) FormatText = value; base.Text = value; } } #region ctor.s public FormattableLabel() : base() { FormatText = string.Empty; } #endregion /// Replaces the format item in a specified string with the string representation of a corresponding object in a specified array. Returns for convenience. /// An object array that contains zero or more objects to format. public string Format(params object[] args) => Text = string.Format(FormatText, args); }