Method One (recommended):
Set DateTimePicker Property ShowCheckBox to True
When the window is initialized, add code this.datetimepicker1.Checked = false;
When you save a date value in storage, you can save the null value according to if (this.datetimepicker1.Checked ==false).
Method Two:
In the window initialization function, add:
This.datetimepicker1.format=datetimepickerformat.custom;
This.datetimepicker1.customformat= "";
In the date Change event, write:
private void Datetimepicker1_valuechanged (object sender, System.EventArgs e)
{
This.datetimepicker1.format=datetimepickerformat.long;
This.datetimepicker1.customformat=null;
}
This enables the DateTimePicker to appear empty when the program is initialized
However, this writing has a problem, when you save the storage, you have to add a judgment if (this.dateTimePicker1.Text.toString () = = ""), Save the empty value; else save This.dateTimePicker1.value.
This writing encountered a bug, has not been resolved, is the date control is empty by default, after the first selection of a date must lose focus to select a new date, do not know why?
Method Three:
Overlay a text box above the date control, and then initialize the text box with a null value, attaching the value to the text box after each date selection.
C # Date Control DateTimePicker Save Null method