C# DateTimePicker控件设置空时间
//在DateTime旁边添加一个清空按钮.
private void btnClearRegTime_Click(object sender, EventArgs e) { MessageBox.Show("Text:" + dtpRegTime.Text + "\nValue:" + dtpRegTime.Value.ToString()); dtpRegTime.CustomFormat = " "; MessageBox.Show("Text:" + dtpRegTime.Text + "\nValue:"+dtpRegTime.Value.ToString()); }
dtpRegTime.CustomFormat = " ";的作用是让dtp.Text为"" ,但dtp.value其实还是时间值。录入数据库的事后要使用dtp.text.