在C#Winforms中显示空日期的方法
我正在使用Visual Studio 2022修改C#Windows表单程序,并正在寻找一种显示空日期字段的方法(最好使用两个“/”以分开一天,月和年)。
以前的开发人员使用了一个蒙版的文本框,该文本框显示“ _ /__/em> ___”,当日期未写入日期时,但客户端想要一种更加直观,更简单的写作方式来编写日期,这使光标放在在第一个位置会自动检查日期是否正确。
我想到使用DateTimePicker,因为它会自动检查书面日期是否正确,并且还具有日历以使其更容易,但客户端不喜欢默认情况下显示日期的事实。我尝试使用自定义空白格式,但是用户需要选择带日历的日期,而不是手动工作,我知道她不会喜欢它。
这是我编写的代码:( DTP的默认格式是自定义的,显示“ / /”
private void dtp_birthdate_ValueChanged(object sender, EventArgs e)
{
dtp_birthdate.Format = DateTimePickerFormat.Short;
}
private void btn_enter_Click_1(object sender, EventArgs e)
{
if (dtp_birthdate.Format == DateTimePickerFormat.Custom)
{
lbl_errorMessage.Visible = true;
errorProvider6.SetError(dtp_birthdate, "The birth date must be written!");
return;
}
}
。我应该使用另一种类型的文本框吗?
谢谢
I'm modifying a C# Windows Form program using Visual Studio 2022 and am looking for a way to display an empty date field (preferably with two "/" to separate the day, month, and year).
The previous developer used a masked textbox which displayed "_/__/___" when a date isn't written, but the client wanted a more intuitive and easier way to write the date, which puts the cursor at the first position automatically, while also checking if the date is correct.
I thought of using a DateTimePicker since it automatically checks if the date written is correct or not, and it also features a calendar to make it easier, but the client doesn't like the fact that a date is displayed by default. I tried using a custom blank format but then the user need to select a date with the calendar and not manually for it to work and I know she will not like it.
Here is the code that I wrote : (the default format of the dtp is a custom one, displaying " / / ".)
private void dtp_birthdate_ValueChanged(object sender, EventArgs e)
{
dtp_birthdate.Format = DateTimePickerFormat.Short;
}
private void btn_enter_Click_1(object sender, EventArgs e)
{
if (dtp_birthdate.Format == DateTimePickerFormat.Custom)
{
lbl_errorMessage.Visible = true;
errorProvider6.SetError(dtp_birthdate, "The birth date must be written!");
return;
}
}
Is there a way to make my dtp display an empty date while not using a custom format ? Should I use another type of textbox?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用此自定义DateTimePicker,
我没有编码
,我在stackoverflow上发现它。简单的用法
控制
Use this custom DateTimePicker,
I didn't code it
, found it I believe here on Stackoverflow.Simple usage
Control