From cd04f9cf19c2620aacfaafdac81988388764441c Mon Sep 17 00:00:00 2001 From: Sunny Date: Thu, 3 Apr 2025 22:43:44 +0800 Subject: [PATCH] =?UTF-8?q?*=20UIDigitalLabel:=20=E5=A2=9E=E5=8A=A0ShowTex?= =?UTF-8?q?t=E5=B1=9E=E6=80=A7=EF=BC=8C=E5=8F=AF=E4=BB=A5=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E6=96=87=E5=AD=97=20#IBY64V?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Controls/UIDigitalLabel.cs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/SunnyUI/Controls/UIDigitalLabel.cs b/SunnyUI/Controls/UIDigitalLabel.cs index 8e766df1..de85eef9 100644 --- a/SunnyUI/Controls/UIDigitalLabel.cs +++ b/SunnyUI/Controls/UIDigitalLabel.cs @@ -19,6 +19,7 @@ * 2023-12-01: V3.6.1 增加文件说明 * 2024-01-23: V3.6.3 更新绘制 * 2024-10-22: V3.7.2 增加DPI支持 + * 2025-04-08: V3.8.2 增加ShowText属性,可以显示文字 #IBY64V ******************************************************************************/ /****************************************************************************** @@ -53,6 +54,22 @@ namespace Sunny.UI BackColor = Color.Black; } + private bool _showText = false; + + [Description("是否显示文字"), Category("SunnyUI"), DefaultValue(false)] + public new bool ShowText + { + get => _showText; + set + { + if (_showText != value) + { + _showText = value; + Invalidate(); + } + } + } + private double digitalValue; [Description("浮点数"), Category("SunnyUI")] @@ -107,7 +124,8 @@ namespace Sunny.UI using Font font = DigitalFont.Instance.GetFont(UIStyles.DPIScale ? DigitalSize / UIDPIScale.SystemDPIScale : DigitalSize); using Brush br = new SolidBrush(ForeColor); - string text = Value.ToString("F" + DecimalPlaces); + string text = ShowText ? Text : Value.ToString("F" + DecimalPlaces); + SizeF sf = e.Graphics.MeasureString(text, font); float y = (Height - sf.Height) / 2.0f + 1 + Padding.Top; float x = Padding.Left;