* UIDatePicker: 修复格式化字符串包含/时显示错误

* UIDateTimePicker: 修复格式化字符串包含/时显示错误
This commit is contained in:
Sunny 2024-08-28 21:55:55 +08:00
parent 51c6da4833
commit 4dd0a284ac
2 changed files with 17 additions and 11 deletions

View File

@ -25,6 +25,7 @@
* 2023-05-14: V3.3.6 * 2023-05-14: V3.3.6
* 2024-06-09: V3.6.6 2 * 2024-06-09: V3.6.6 2
* 2024-07-13: V3.6.7 * 2024-07-13: V3.6.7
* 2024-08-28: V3.7.0 /
******************************************************************************/ ******************************************************************************/
using System; using System;
@ -235,7 +236,7 @@ namespace Sunny.UI
private void UIDatePicker_TextChanged(object sender, EventArgs e) private void UIDatePicker_TextChanged(object sender, EventArgs e)
{ {
if (Text.Length == MaxLength) if (Text.Length == MaxLength && !DropSetted)
{ {
try try
{ {
@ -316,6 +317,7 @@ namespace Sunny.UI
ItemForm = new UIDropDown(item); ItemForm = new UIDropDown(item);
} }
private bool DropSetted = false;
[Description("选中日期"), Category("SunnyUI")] [Description("选中日期"), Category("SunnyUI")]
public DateTime Value public DateTime Value
{ {
@ -325,19 +327,22 @@ namespace Sunny.UI
if (value < new DateTime(1900, 1, 1)) if (value < new DateTime(1900, 1, 1))
value = new DateTime(1900, 1, 1); value = new DateTime(1900, 1, 1);
DropSetted = true;
switch (ShowType) switch (ShowType)
{ {
case UIDateType.YearMonthDay: case UIDateType.YearMonthDay:
Text = value.ToString(dateFormat); Text = value.ToString(dateFormat, CultureInfo.InvariantCulture);
break; break;
case UIDateType.YearMonth: case UIDateType.YearMonth:
Text = value.ToString(dateYearMonthFormat); Text = value.ToString(dateYearMonthFormat, CultureInfo.InvariantCulture);
break; break;
case UIDateType.Year: case UIDateType.Year:
Text = value.ToString(dateYearFormat); Text = value.ToString(dateYearFormat, CultureInfo.InvariantCulture);
break; break;
} }
DropSetted = false;
if (item.Date != value) if (item.Date != value)
{ {
item.Date = value; item.Date = value;

View File

@ -23,11 +23,13 @@
* 2021-04-15: V3.0.3 ShowToday显示今日属性 * 2021-04-15: V3.0.3 ShowToday显示今日属性
* 2024-06-09: V3.6.6 2 * 2024-06-09: V3.6.6 2
* 2024-07-13: V3.6.7 * 2024-07-13: V3.6.7
* 2024-08-28: V3.7.0 /
******************************************************************************/ ******************************************************************************/
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using System.Drawing; using System.Drawing;
using System.Globalization;
using System.Windows.Forms; using System.Windows.Forms;
namespace Sunny.UI namespace Sunny.UI
@ -105,7 +107,7 @@ namespace Sunny.UI
private void UIDatePicker_TextChanged(object sender, EventArgs e) private void UIDatePicker_TextChanged(object sender, EventArgs e)
{ {
if (Text.Length == MaxLength) if (Text.Length == MaxLength && !DropSetted)
{ {
try try
{ {
@ -163,6 +165,7 @@ namespace Sunny.UI
ItemForm = new UIDropDown(item); ItemForm = new UIDropDown(item);
} }
private bool DropSetted = false;
[Description("选中日期时间"), Category("SunnyUI")] [Description("选中日期时间"), Category("SunnyUI")]
public DateTime Value public DateTime Value
{ {
@ -171,7 +174,10 @@ namespace Sunny.UI
{ {
if (value < new DateTime(1900, 1, 1)) if (value < new DateTime(1900, 1, 1))
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) if (item.Date != value)
{ {
@ -188,11 +194,6 @@ namespace Sunny.UI
private void UIDatetimePicker_ButtonClick(object sender, EventArgs e) 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.Date = Value;
item.ShowToday = ShowToday; item.ShowToday = ShowToday;
item.PrimaryColor = RectColor; item.PrimaryColor = RectColor;