清除c#窗口中的DateTimePicker控件
本文关键字:DateTimePicker 控件 窗口 清除 | 更新日期: 2023-09-27 18:15:59
我想清除DateTimePicker控件值当我点击清除按钮,但我不能用简单的双引号做到这一点,所以请帮助我
tbAddress.Text = "";
dtpBirth.Value = "";
cBoxGender.SelectedIndex = -1;
应该可以了
dtpBirth.CustomFormat = " ";
dtpBirth.Format = DateTimePickerFormat.Custom;
将清除输入框。
try is
dateTimePickerDOB.Value = DateTimePicker.MinimumDateTime
在这里,您的日期和时间将是DateTimePicker中的最小日期和时间,dateTimePickerDOB
表示您的设计(名称)
或
尝试清除日期
dateTimePicker_dob.Text = string.Empty;
这里的dateTimePickerDOB
表示您的Design(name)
DateTimePicker.Value
来自DateTime
类型,而不是String
。
dtpBirth.Value = DateTime.Now;
你可以这样做:
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;
}