diff --git a/SunnyUI/Controls/DropItem/UIColorItem.cs b/SunnyUI/Controls/DropItem/UIColorItem.cs index 285df230..41100672 100644 --- a/SunnyUI/Controls/DropItem/UIColorItem.cs +++ b/SunnyUI/Controls/DropItem/UIColorItem.cs @@ -259,8 +259,6 @@ namespace Sunny.UI this.edtA.Cursor = System.Windows.Forms.Cursors.IBeam; this.edtA.FillColor = System.Drawing.Color.White; this.edtA.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.edtA.HasMaximum = true; - this.edtA.HasMinimum = true; this.edtA.Location = new System.Drawing.Point(29, 197); this.edtA.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.edtA.Maximum = 255D; @@ -278,8 +276,6 @@ namespace Sunny.UI this.edtR.Cursor = System.Windows.Forms.Cursors.IBeam; this.edtR.FillColor = System.Drawing.Color.White; this.edtR.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.edtR.HasMaximum = true; - this.edtR.HasMinimum = true; this.edtR.Location = new System.Drawing.Point(93, 197); this.edtR.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.edtR.Maximum = 255D; @@ -297,8 +293,6 @@ namespace Sunny.UI this.edtG.Cursor = System.Windows.Forms.Cursors.IBeam; this.edtG.FillColor = System.Drawing.Color.White; this.edtG.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.edtG.HasMaximum = true; - this.edtG.HasMinimum = true; this.edtG.Location = new System.Drawing.Point(158, 197); this.edtG.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.edtG.Maximum = 255D; @@ -316,8 +310,6 @@ namespace Sunny.UI this.edtB.Cursor = System.Windows.Forms.Cursors.IBeam; this.edtB.FillColor = System.Drawing.Color.White; this.edtB.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.edtB.HasMaximum = true; - this.edtB.HasMinimum = true; this.edtB.Location = new System.Drawing.Point(222, 197); this.edtB.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.edtB.Maximum = 255D; diff --git a/SunnyUI/Controls/UIDoubleUpDown.cs b/SunnyUI/Controls/UIDoubleUpDown.cs index b0e31dfb..40721579 100644 --- a/SunnyUI/Controls/UIDoubleUpDown.cs +++ b/SunnyUI/Controls/UIDoubleUpDown.cs @@ -25,6 +25,8 @@ * 2022-02-24: V3.1.1 可以设置按钮大小和颜色 * 2022-05-05: V3.1.8 增加禁止输入属性 * 2022-09-16: V3.2.4 增加是否可以双击输入属性 + * 2022-11-12: V3.2.8 修改整数、浮点数大小离开判断为实时输入判断 + * 2022-11-12: V3.2.8 删除MaximumEnabled、MinimumEnabled、HasMaximum、HasMinimum属性 ******************************************************************************/ using System; @@ -51,7 +53,6 @@ namespace Sunny.UI edit.Parent = pnlValue; edit.Visible = false; edit.BorderStyle = BorderStyle.None; - edit.TextChanged += Edit_TextChanged; edit.Leave += Edit_Leave; pnlValue.Paint += PnlValue_Paint; } @@ -89,14 +90,7 @@ namespace Sunny.UI { edit.Visible = false; pnlValue.FillColor = pnlColor; - } - } - - private void Edit_TextChanged(object sender, EventArgs e) - { - if (edit != null && edit.Visible) - { - Value = edit.Text.ToDouble(); + Value = edit.DoubleValue; } } @@ -132,10 +126,13 @@ namespace Sunny.UI get => _value; set { - value = CheckMaxMin(value); - _value = value; - pnlValue.Text = _value.ToString("F" + decLength); - ValueChanged?.Invoke(this, _value); + value = edit.CheckMaxMin(value); + if (_value != value) + { + _value = value; + pnlValue.Text = _value.ToString("F" + decLength); + ValueChanged?.Invoke(this, _value); + } } } @@ -188,111 +185,20 @@ namespace Sunny.UI } } - private double _maximum = double.MaxValue; - private double _minimum = double.MinValue; - - [DefaultValue(double.MaxValue)] + [DefaultValue(typeof(double), "2147483647")] [Description("最大值"), Category("SunnyUI")] public double Maximum { - get => _maximum; - set - { - _maximum = value; - if (_maximum < _minimum) - _minimum = _maximum; - - Value = CheckMaxMin(Value); - edit.MaxValue = _maximum; - Invalidate(); - } + get => edit.MaxValue; + set => edit.MaxValue = value; } - [DefaultValue(double.MinValue)] + [DefaultValue(typeof(double), "-2147483648")] [Description("最小值"), Category("SunnyUI")] public double Minimum { - get => _minimum; - set - { - _minimum = value; - if (_minimum > _maximum) - _maximum = _minimum; - - Value = CheckMaxMin(Value); - edit.MinValue = _minimum; - Invalidate(); - } - } - - private double CheckMaxMin(double value) - { - if (hasMaximum) - { - if (value > _maximum) - value = _maximum; - } - - if (hasMinimum) - { - if (value < _minimum) - value = _minimum; - } - - return value; - } - - [DefaultValue(false)] - [Description("是否判断最大值显示"), Category("SunnyUI")] - public bool MaximumEnabled - { - get => HasMaximum; - set => HasMaximum = value; - } - - [DefaultValue(false)] - [Description("是否判断最小值显示"), Category("SunnyUI")] - public bool MinimumEnabled - { - get => HasMinimum; - set => HasMinimum = value; - } - - private bool hasMaximum; - private bool hasMinimum; - - [DefaultValue(false), Browsable(false)] - [Description("检查最大值"), Category("SunnyUI")] - public bool HasMaximum - { - get => hasMaximum; - set - { - if (hasMaximum != value) - { - hasMaximum = value; - Value = CheckMaxMin(Value); - edit.HasMaxValue = value; - Invalidate(); - } - } - } - - [DefaultValue(false), Browsable(false)] - [Description("检查最小值"), Category("SunnyUI")] - public bool HasMinimum - { - get => hasMinimum; - set - { - if (hasMinimum != value) - { - hasMinimum = value; - Value = CheckMaxMin(Value); - edit.HasMinValue = value; - Invalidate(); - } - } + get => edit.MinValue; + set => edit.MinValue = value; } [DefaultValue(true)] diff --git a/SunnyUI/Controls/UIEdit.cs b/SunnyUI/Controls/UIEdit.cs index 871f3036..4cecde46 100644 --- a/SunnyUI/Controls/UIEdit.cs +++ b/SunnyUI/Controls/UIEdit.cs @@ -377,36 +377,6 @@ namespace Sunny.UI } } - [Browsable(false), DefaultValue(false)] - public bool HasMaxValue { get; set; } - //{ - // get => hasMaxValue; - // set - // { - // if (hasMaxValue != value) - // { - // hasMaxValue = value; - // CheckMaxMin(); - // Invalidate(); - // } - // } - //} - - [Browsable(false), DefaultValue(false)] - public bool HasMinValue { get; set; } - //{ - // get => hasMinValue; - // set - // { - // if (hasMinValue != value) - // { - // hasMinValue = value; - // CheckMaxMin(); - // Invalidate(); - // } - // } - //} - [DefaultValue(0)] public double DoubleValue { @@ -417,8 +387,8 @@ namespace Sunny.UI } set { - CheckMaxMin(); Text = value.ToString("f" + decLength); + CheckMaxMin(); } } @@ -432,8 +402,8 @@ namespace Sunny.UI } set { - CheckMaxMin(); Text = value.ToString(); + CheckMaxMin(); } } @@ -584,6 +554,36 @@ namespace Sunny.UI return true; } + public double CheckMaxMin(double value) + { + if (_uiEditType == UITextBox.UIEditType.Integer) + { + if (value > MaxValue) + value = (int)MaxValue; + if (value < MinValue) + value = (int)MinValue; + + Text = value.ToString(); + SelectionStart = Text.Length; + return value; + } + + if (_uiEditType == UITextBox.UIEditType.Double) + { + if (value > MaxValue) + value = MaxValue; + + if (value < MinValue) + value = MinValue; + + Text = value.ToString("f" + decLength); + SelectionStart = Text.Length; + return value; + } + + return value; + } + public void CheckMaxMin() { if (_uiEditType == UITextBox.UIEditType.Integer) @@ -592,12 +592,18 @@ namespace Sunny.UI if (!int.TryParse(Text, out var a)) return; if (a > MaxValue) + { a = (int)MaxValue; - if (a < MinValue) - a = (int)MinValue; + Text = a.ToString(); + SelectionStart = Text.Length; + } - Text = a.ToString(); - SelectionStart = Text.Length; + if (a < MinValue) + { + a = (int)MinValue; + Text = a.ToString(); + SelectionStart = Text.Length; + } } if (_uiEditType == UITextBox.UIEditType.Double) @@ -606,13 +612,18 @@ namespace Sunny.UI if (!double.TryParse(Text, out var a)) return; if (a > MaxValue) + { a = MaxValue; + Text = a.ToString("f" + decLength); + SelectionStart = Text.Length; + } if (a < MinValue) + { a = MinValue; - - Text = a.ToString("f" + decLength); - SelectionStart = Text.Length; + Text = a.ToString("f" + decLength); + SelectionStart = Text.Length; + } } } diff --git a/SunnyUI/Controls/UIIntegerUpDown.cs b/SunnyUI/Controls/UIIntegerUpDown.cs index 311b3cc2..3aa79d40 100644 --- a/SunnyUI/Controls/UIIntegerUpDown.cs +++ b/SunnyUI/Controls/UIIntegerUpDown.cs @@ -24,6 +24,8 @@ * 2022-02-24: V3.1.1 可以设置按钮大小和颜色 * 2022-05-05: V3.1.8 增加禁止输入属性 * 2022-09-16: V3.2.4 增加是否可以双击输入属性 + * 2022-11-12: V3.2.8 修改整数、浮点数大小离开判断为实时输入判断 + * 2022-11-12: V3.2.8 删除MaximumEnabled、MinimumEnabled、HasMaximum、HasMinimum属性 ******************************************************************************/ using System; @@ -48,7 +50,6 @@ namespace Sunny.UI edit.Parent = pnlValue; edit.Visible = false; edit.BorderStyle = BorderStyle.None; - edit.TextChanged += Edit_TextChanged; edit.Leave += Edit_Leave; pnlValue.Paint += PnlValue_Paint; } @@ -86,14 +87,7 @@ namespace Sunny.UI { edit.Visible = false; pnlValue.FillColor = pnlColor; - } - } - - private void Edit_TextChanged(object sender, EventArgs e) - { - if (edit != null && edit.Visible) - { - Value = edit.Text.ToInt(); + Value = edit.IntValue; } } @@ -108,7 +102,7 @@ namespace Sunny.UI get => _value; set { - value = CheckMaxMin(value); + value = (int)edit.CheckMaxMin(value); if (_value != value) { _value = value; @@ -174,111 +168,20 @@ namespace Sunny.UI } } - private int _maximum = int.MaxValue; - private int _minimum = int.MinValue; - [Description("最大值"), Category("SunnyUI")] [DefaultValue(int.MaxValue)] public int Maximum { - get => _maximum; - set - { - _maximum = value; - if (_maximum < _minimum) - _minimum = _maximum; - - Value = CheckMaxMin(Value); - edit.MaxValue = _maximum; - Invalidate(); - } + get => (int)edit.MaxValue; + set => edit.MaxValue = value; } [Description("最小值"), Category("SunnyUI")] [DefaultValue(int.MinValue)] public int Minimum { - get => _minimum; - set - { - _minimum = value; - if (_minimum > _maximum) - _maximum = _minimum; - - Value = CheckMaxMin(Value); - edit.MinValue = _maximum; - Invalidate(); - } - } - - private int CheckMaxMin(int value) - { - if (hasMaximum) - { - if (value > _maximum) - value = _maximum; - } - - if (hasMinimum) - { - if (value < _minimum) - value = _minimum; - } - - return value; - } - - [DefaultValue(false)] - [Description("是否判断最大值显示"), Category("SunnyUI")] - public bool MaximumEnabled - { - get => HasMaximum; - set => HasMaximum = value; - } - - [DefaultValue(false)] - [Description("是否判断最小值显示"), Category("SunnyUI")] - public bool MinimumEnabled - { - get => HasMinimum; - set => HasMinimum = value; - } - - private bool hasMaximum; - private bool hasMinimum; - - [DefaultValue(false), Browsable(false)] - [Description("检查最大值"), Category("SunnyUI")] - public bool HasMaximum - { - get => hasMaximum; - set - { - if (hasMaximum != value) - { - hasMaximum = value; - Value = CheckMaxMin(Value); - edit.HasMaxValue = value; - Invalidate(); - } - } - } - - [DefaultValue(false), Browsable(false)] - [Description("检查最小值"), Category("SunnyUI")] - public bool HasMinimum - { - get => hasMinimum; - set - { - if (hasMinimum != value) - { - hasMinimum = value; - Value = CheckMaxMin(Value); - edit.HasMinValue = value; - Invalidate(); - } - } + get => (int)edit.MinValue; + set => edit.MinValue = value; } [DefaultValue(true)] diff --git a/SunnyUI/Controls/UIPagination.cs b/SunnyUI/Controls/UIPagination.cs index 877cf154..6f41739f 100644 --- a/SunnyUI/Controls/UIPagination.cs +++ b/SunnyUI/Controls/UIPagination.cs @@ -682,12 +682,10 @@ namespace Sunny.UI this.edtPage.Cursor = System.Windows.Forms.Cursors.IBeam; this.edtPage.DoubleValue = 10D; this.edtPage.Font = new System.Drawing.Font("微软雅黑", 12F); - this.edtPage.HasMinimum = true; this.edtPage.IntValue = 10; this.edtPage.Location = new System.Drawing.Point(28, 0); this.edtPage.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.edtPage.Minimum = 1D; - this.edtPage.MinimumEnabled = true; this.edtPage.MinimumSize = new System.Drawing.Size(1, 1); this.edtPage.Name = "edtPage"; this.edtPage.Padding = new System.Windows.Forms.Padding(5); @@ -816,7 +814,6 @@ namespace Sunny.UI b16.Visible = true; PageCount = TotalCount.Mod(PageSize) == 0 ? TotalCount / PageSize : TotalCount / PageSize + 1; - edtPage.HasMaximum = true; edtPage.Maximum = PageCount; if (activePage >= PageCount) diff --git a/SunnyUI/Controls/UITextBox.cs b/SunnyUI/Controls/UITextBox.cs index b2cb60cc..03e9189a 100644 --- a/SunnyUI/Controls/UITextBox.cs +++ b/SunnyUI/Controls/UITextBox.cs @@ -42,6 +42,7 @@ * 2022-09-16: V3.2.4 修改右侧Button可能不显示的问题 * 2022-11-03: V3.2.6 增加了可设置垂直滚动条宽度的属性 * 2022-11-12: V3.2.8 修改整数、浮点数大小离开判断为实时输入判断 + * 2022-11-12: V3.2.8 删除MaximumEnabled、MinimumEnabled、HasMaximum、HasMinimum属性 ******************************************************************************/ using System; @@ -729,38 +730,6 @@ namespace Sunny.UI set => edit.MinValue = value; } - [DefaultValue(false), Browsable(false)] - [Description("是否判断最大值显示"), Category("SunnyUI")] - public bool MaximumEnabled - { - get => HasMaximum; - set => HasMaximum = value; - } - - [DefaultValue(false), Browsable(false)] - [Description("是否判断最小值显示"), Category("SunnyUI")] - public bool MinimumEnabled - { - get => HasMinimum; - set => HasMinimum = value; - } - - [DefaultValue(false), Browsable(false)] - [Description("是否判断最大值显示"), Category("SunnyUI")] - public bool HasMaximum - { - get => edit.HasMaxValue; - set => edit.HasMaxValue = value; - } - - [DefaultValue(false), Browsable(false)] - [Description("是否判断最小值显示"), Category("SunnyUI")] - public bool HasMinimum - { - get => edit.HasMinValue; - set => edit.HasMinValue = value; - } - [DefaultValue(0.00)] [Description("浮点返回值"), Category("SunnyUI")] public double DoubleValue diff --git a/SunnyUI/Forms/UIFormHelper.cs b/SunnyUI/Forms/UIFormHelper.cs index aed90033..a880846c 100644 --- a/SunnyUI/Forms/UIFormHelper.cs +++ b/SunnyUI/Forms/UIFormHelper.cs @@ -386,8 +386,6 @@ namespace Sunny.UI frm.Editor.MaxLength = 11; frm.Editor.Minimum = minimum; frm.Editor.Maximum = maximum; - frm.Editor.HasMaximum = true; - frm.Editor.HasMinimum = true; if (showMask) frm.ShowDialogWithMask(); else @@ -476,8 +474,6 @@ namespace Sunny.UI frm.CheckInputEmpty = checkEmpty; frm.Editor.Minimum = minimum; frm.Editor.Maximum = maximum; - frm.Editor.HasMaximum = true; - frm.Editor.HasMinimum = true; if (showMask) frm.ShowDialogWithMask(); else