我遇到了dateTimePicker
课程的问题。我需要在构造上使用DateTimePicker
空,我通过这个来实现:
dateTimePicker1.MaxDate = DateTime.Now; // Ensures no future dates are set.
dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = " ";
我的问题是,现在用户必须在日历上实际点击以输入日期,而不是使用向上键,或键入。无论如何,我可以像我在构造函数中那样初始化dateTimePicker1
到" "
,但也允许用户使用箭头键来“激活”它而不是点击日历?
我的ValueChanged
更改了活动
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
dateTimePicker1.CustomFormat = "dd/MM/yyyy hh:mm:ss";
if (dateTimePicker1.Checked == true)
{
dateTimePicker1.Enabled = true;
dateTimePicker1.Format = DateTimePickerFormat.Short;
}
else if (dateTimePicker1.Checked == false)
{
dateTimePicker1.Enabled = false;
dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = " ";
}
}
我知道DateTimePicker
不容易为空,因此你必须对类的扩展进行修改,但这是一个快速修复。任何想法将不胜感激。