winforms 可为空的日期时间选取器

aiqt4smr  于 2022-11-16  发布在  其他
关注(0)|答案(2)|浏览(180)

我希望用户在隐藏DateTimePicker时将其设置为Null。我编写了一个代码,但它只显示年份部分“00”,并显示明天的日期。如“01-Jan-00”。我希望整个日期-月份-年份为Null。
这是我使用的代码:

dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = " ";
mdfafbf1

mdfafbf12#

请参阅此处msdn

public void CreateMyDateTimePicker()
{
   // Create a new DateTimePicker control and initialize it.
   DateTimePicker dateTimePicker1 = new DateTimePicker();

   // Set the MinDate and MaxDate.
   dateTimePicker1.MinDate = new DateTime(1985, 6, 20);
   dateTimePicker1.MaxDate = DateTime.Today;

   // Set the CustomFormat string.
   dateTimePicker1.CustomFormat = "MMMM dd, yyyy - dddd";
   dateTimePicker1.Format = DateTimePickerFormat.Custom;

   // Show the CheckBox and display the control as an up-down control.
   dateTimePicker1.ShowCheckBox = true;
   dateTimePicker1.ShowUpDown = true;
}

相关问题