如何在DateTimePicker上提示用户?
问题描述:
有一种检查此类空文本框的已知方法
There''s a known way to check for empty textboxes like these
Sub Check_Textbox()
Dim r As DialogResult
If txtStaffID.Text = ""
Then
r = MessageBox.Show("Please try again.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
但是,有没有一种方法可以在DateTimepicker上提示用户?这是我希望系统提示用户的内容和方式:
DateTimePicker检查日期.如果不是提前3天,它将提示用户并禁止执行任何操作.
可以采取上述行动吗?如果是这样,我能知道它的编码吗?在此先谢谢您.
But is there a way to prompt the user on a DateTimepicker? here is what and how i want the system to prompt the user:
The DateTimePicker checks the date. If it''s not 3 days in advance, it will prompt the user and disallow any action.
Is the above action possible? If so, can i know the codings to it? Thanks in advance.
答
您可以考虑使用DateTimePicker
ValueChanged
^ ].
处理此事件,从事件的参数中读取日期值,如果数据不符合条件,则显示一个类似于您对textbox
进行此操作的方式的消息框.
You can consider using theDateTimePicker
ValueChanged
event[^].
Handle this event, read the date value (from the event''s parameters) and if the data does not meet the condition, display a message box similar to the way you were doing this for thetextbox
.
是的,您需要编写代码以检查日期时间选择器中的日期.如果使用DateTime.Now从另一个日期时间中减去一个日期时间,则将获得一个Timepan.如果天差< 3,然后显示您的消息.
Yes, you need to write code that checks the date in your datetime picker. If you subtract one date time from another, using DateTime.Now, you get a Timespan. If the difference in days < 3, then you show your message.