* UIRoundProcess:增加显示小数位数

This commit is contained in:
Sunny 2021-10-18 16:00:11 +08:00
parent 5ece1cc39a
commit 46eccd7b74
6 changed files with 42 additions and 8 deletions

Binary file not shown.

Binary file not shown.

View File

@ -175,6 +175,7 @@ namespace Sunny.UI.Demo
// uiRoundProcess2 // uiRoundProcess2
// //
this.uiRoundProcess2.BackColor = System.Drawing.Color.Transparent; this.uiRoundProcess2.BackColor = System.Drawing.Color.Transparent;
this.uiRoundProcess2.DecimalPlaces = 0;
this.uiRoundProcess2.Font = new System.Drawing.Font("微软雅黑", 12F); this.uiRoundProcess2.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiRoundProcess2.ForeColor = System.Drawing.Color.White; this.uiRoundProcess2.ForeColor = System.Drawing.Color.White;
this.uiRoundProcess2.Inner = 0; this.uiRoundProcess2.Inner = 0;
@ -186,7 +187,7 @@ namespace Sunny.UI.Demo
this.uiRoundProcess2.Style = Sunny.UI.UIStyle.Custom; this.uiRoundProcess2.Style = Sunny.UI.UIStyle.Custom;
this.uiRoundProcess2.StyleCustomMode = true; this.uiRoundProcess2.StyleCustomMode = true;
this.uiRoundProcess2.TabIndex = 93; this.uiRoundProcess2.TabIndex = 93;
this.uiRoundProcess2.Text = "0.0%"; this.uiRoundProcess2.Text = "0%";
// //
// uiLine9 // uiLine9
// //

View File

@ -135,7 +135,7 @@ namespace Sunny.UI
processSize = posValue * Height * 1.0f / Maximum; processSize = posValue * Height * 1.0f / Maximum;
if (ShowPercent) if (ShowPercent)
processText = (posValue * 100.0 / maximum).ToString("F" + DecimalCount) + "%"; processText = (posValue * 100.0 / maximum).ToString("F" + decimalCount) + "%";
else else
processText = posValue.ToString(); processText = posValue.ToString();
@ -204,10 +204,19 @@ namespace Sunny.UI
} }
} }
[Description("显示文字小数位数"), Category("SunnyUI")]
[DefaultValue(1)]
public int DecimalPlaces
{
get => decimalCount;
set => decimalCount = Math.Max(value, 0);
}
private int decimalCount = 1; private int decimalCount = 1;
[Description("显示文字小数位数"), Category("SunnyUI")] [Description("显示文字小数位数"), Category("SunnyUI")]
[DefaultValue(1)] [DefaultValue(1), Browsable(false)]
[Obsolete("请用DecimalPlaces代替。")]
public int DecimalCount public int DecimalCount
{ {
get => decimalCount; get => decimalCount;

View File

@ -17,6 +17,7 @@
* : 2021-04-08 * : 2021-04-08
* *
* 2021-04-08: V3.0.2 * 2021-04-08: V3.0.2
* 2021-10-18: V3.0.8
******************************************************************************/ ******************************************************************************/
using System; using System;
@ -48,6 +49,20 @@ namespace Sunny.UI
ShowRect = false; ShowRect = false;
} }
[Description("显示文字小数位数"), Category("SunnyUI")]
[DefaultValue(1)]
public int DecimalPlaces
{
get => decimalCount;
set
{
decimalCount = Math.Max(value, 0);
Text = (posValue * 100.0 / maximum).ToString("F" + decimalCount) + "%";
}
}
private int decimalCount = 1;
private int maximum = 100; private int maximum = 100;
[DefaultValue(100)] [DefaultValue(100)]
@ -138,7 +153,7 @@ namespace Sunny.UI
{ {
posValue = Math.Max(value, 0); posValue = Math.Max(value, 0);
posValue = Math.Min(posValue, maximum); posValue = Math.Min(posValue, maximum);
Text = (posValue * 100.0 / maximum).ToString("F1") + "%"; Text = (posValue * 100.0 / maximum).ToString("F" + decimalCount) + "%";
ValueChanged?.Invoke(this, posValue); ValueChanged?.Invoke(this, posValue);
Invalidate(); Invalidate();
} }

View File

@ -19,6 +19,7 @@
* 2020-05-05: V2.2.5 * 2020-05-05: V2.2.5
******************************************************************************/ ******************************************************************************/
using System;
using System.ComponentModel; using System.ComponentModel;
namespace Sunny.UI namespace Sunny.UI
@ -32,14 +33,14 @@ namespace Sunny.UI
Description = UILocalize.SystemProcessing; Description = UILocalize.SystemProcessing;
} }
public UIStatusForm(int max, string desc, int decimalCount = 1) public UIStatusForm(int max, string desc, int decimalPlaces = 1)
{ {
InitializeComponent(); InitializeComponent();
Maximum = max; Maximum = max;
Description = desc; Description = desc;
Value = 0; Value = 0;
DecimalCount = decimalCount; DecimalPlaces = decimalPlaces;
} }
[DefaultValue(100)] [DefaultValue(100)]
@ -99,10 +100,18 @@ namespace Sunny.UI
set => labelDescription.Text = value; set => labelDescription.Text = value;
} }
public int DecimalPlaces
{
get => processBar.DecimalPlaces;
set => processBar.DecimalPlaces = value;
}
[Obsolete("请用DecimalPlaces代替。")]
public int DecimalCount public int DecimalCount
{ {
get => processBar.DecimalCount; get => processBar.DecimalPlaces;
set => processBar.DecimalCount = value; set => processBar.DecimalPlaces = value;
} }
private delegate void SetTextHandler(string text); private delegate void SetTextHandler(string text);