From 4dd0a284ace808edbeee8b691382054503618c64 Mon Sep 17 00:00:00 2001 From: Sunny Date: Wed, 28 Aug 2024 21:55:55 +0800 Subject: [PATCH] =?UTF-8?q?*=20UIDatePicker:=20=E4=BF=AE=E5=A4=8D=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E5=8C=96=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=8C=85=E5=90=AB?= =?UTF-8?q?/=E6=97=B6=E6=98=BE=E7=A4=BA=E9=94=99=E8=AF=AF=20*=20UIDateTime?= =?UTF-8?q?Picker:=20=E4=BF=AE=E5=A4=8D=E6=A0=BC=E5=BC=8F=E5=8C=96?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=8C=85=E5=90=AB/=E6=97=B6?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Controls/UIDatePicker.cs | 13 +++++++++---- SunnyUI/Controls/UIDateTimePicker.cs | 15 ++++++++------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/SunnyUI/Controls/UIDatePicker.cs b/SunnyUI/Controls/UIDatePicker.cs index 85ba0ca1..29265535 100644 --- a/SunnyUI/Controls/UIDatePicker.cs +++ b/SunnyUI/Controls/UIDatePicker.cs @@ -25,6 +25,7 @@ * 2023-05-14: V3.3.6 修复文字格式化显示问题 * 2024-06-09: V3.6.6 下拉框可选放大倍数为2 * 2024-07-13: V3.6.7 修改选择日期在下拉框中显示方式 + * 2024-08-28: V3.7.0 修复格式化字符串包含/时显示错误 ******************************************************************************/ using System; @@ -235,7 +236,7 @@ namespace Sunny.UI private void UIDatePicker_TextChanged(object sender, EventArgs e) { - if (Text.Length == MaxLength) + if (Text.Length == MaxLength && !DropSetted) { try { @@ -316,6 +317,7 @@ namespace Sunny.UI ItemForm = new UIDropDown(item); } + private bool DropSetted = false; [Description("选中日期"), Category("SunnyUI")] public DateTime Value { @@ -325,19 +327,22 @@ namespace Sunny.UI if (value < new DateTime(1900, 1, 1)) value = new DateTime(1900, 1, 1); + DropSetted = true; switch (ShowType) { case UIDateType.YearMonthDay: - Text = value.ToString(dateFormat); + Text = value.ToString(dateFormat, CultureInfo.InvariantCulture); break; case UIDateType.YearMonth: - Text = value.ToString(dateYearMonthFormat); + Text = value.ToString(dateYearMonthFormat, CultureInfo.InvariantCulture); break; case UIDateType.Year: - Text = value.ToString(dateYearFormat); + Text = value.ToString(dateYearFormat, CultureInfo.InvariantCulture); break; } + DropSetted = false; + if (item.Date != value) { item.Date = value; diff --git a/SunnyUI/Controls/UIDateTimePicker.cs b/SunnyUI/Controls/UIDateTimePicker.cs index 9cba0d0d..8f80db9f 100644 --- a/SunnyUI/Controls/UIDateTimePicker.cs +++ b/SunnyUI/Controls/UIDateTimePicker.cs @@ -23,11 +23,13 @@ * 2021-04-15: V3.0.3 增加ShowToday显示今日属性 * 2024-06-09: V3.6.6 下拉框可选放大倍数为2 * 2024-07-13: V3.6.7 修改选择日期在下拉框中显示方式 + * 2024-08-28: V3.7.0 修复格式化字符串包含/时显示错误 ******************************************************************************/ using System; using System.ComponentModel; using System.Drawing; +using System.Globalization; using System.Windows.Forms; namespace Sunny.UI @@ -105,7 +107,7 @@ namespace Sunny.UI private void UIDatePicker_TextChanged(object sender, EventArgs e) { - if (Text.Length == MaxLength) + if (Text.Length == MaxLength && !DropSetted) { try { @@ -163,6 +165,7 @@ namespace Sunny.UI ItemForm = new UIDropDown(item); } + private bool DropSetted = false; [Description("选中日期时间"), Category("SunnyUI")] public DateTime Value { @@ -171,7 +174,10 @@ namespace Sunny.UI { if (value < new DateTime(1900, 1, 1)) value = new DateTime(1900, 1, 1); - Text = value.ToString(dateFormat); + + DropSetted = true; + Text = value.ToString(dateFormat, CultureInfo.InvariantCulture); + DropSetted = false; if (item.Date != value) { @@ -188,11 +194,6 @@ namespace Sunny.UI private void UIDatetimePicker_ButtonClick(object sender, EventArgs e) { - if (DateTime.TryParse(Text, out DateTime dt)) - Value = dt; - else - Value = DateTime.Now; - item.Date = Value; item.ShowToday = ShowToday; item.PrimaryColor = RectColor;