Csharp/C#教程:如何使用c#清除Windows应用程序中的datetimepicker值?分享


如何使用c#清除Windows应用程序中的datetimepicker值?

我想点击清除按钮时清除我的datetimepicker对象值。

我只是这样试过:

datetimepicker1.Format = DateTimePickerFormat.Short; datetimepicker1.CustomFormat = " "; 

是的,它清除了datetimepicker控件下的值。 但问题是在清除了值之后,我想在选择特定日期后选择日期,该日期不会显示在datetimepicker对象中。 有什么问题?

这应该符合你的目的。 逻辑是将日期重置为最小值,然后使用ValueChanged事件使用您已尝试的内容将其隐藏。

上述就是C#学习教程:如何使用c#清除Windows应用程序中的datetimepicker值?分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 private void DateTimePicker1_ValueChanged(object sender, EventArgs e) { if (dateTimePicker1.Value == DateTimePicker.MinimumDateTime) { dateTimePicker1.Value = DateTime.Now; // This is required in order to show current month/year when user reopens the date popup. dateTimePicker1.Format = DateTimePickerFormat.Custom; dateTimePicker1.CustomFormat = " "; } else { dateTimePicker1.Format = DateTimePickerFormat.Short; } } private void Clear_Click(object sender, EventArgs e) { dateTimePicker1.Value = DateTimePicker.MinimumDateTime; } 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1031708.html

(0)
上一篇 2022年1月14日
下一篇 2022年1月14日

精彩推荐