Formattable UI labels
This commit is contained in:
parent
0a106e64d8
commit
b60a854de0
6 changed files with 195 additions and 73 deletions
32
Source/LibationWinForms/FormattableLabel.cs
Normal file
32
Source/LibationWinForms/FormattableLabel.cs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace LibationWinForms
|
||||
{
|
||||
public class FormattableLabel : Label
|
||||
{
|
||||
public string FormatText { get; set; }
|
||||
|
||||
/// <summary>Text set: first non-null, non-whitespace <see cref="Text"/> set is also saved as <see cref="FormatText"/></summary>
|
||||
public override string Text
|
||||
{
|
||||
get => base.Text;
|
||||
set
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(FormatText))
|
||||
FormatText = value;
|
||||
|
||||
base.Text = value;
|
||||
}
|
||||
}
|
||||
|
||||
#region ctor.s
|
||||
public FormattableLabel() : base() { }
|
||||
#endregion
|
||||
|
||||
/// <summary>Replaces the format item in a specified string with the string representation of a corresponding object in a specified array. Returns <see cref="Text"/> for convenience.</summary>
|
||||
/// <param name="args">An object array that contains zero or more objects to format.</param>
|
||||
public string Format(params object[] args) => Text = string.Format(FormatText, args);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue