如何验证Datetimepicker [英] How to Validate Datetimepicker

查看:87
本文介绍了如何验证Datetimepicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



如何验证日期时间选择器,这里我只希望在基于月份的日期时间选择器中显示日期,另外一个ComboBox控件上共有12个月可用,那么哪个月用户选择我想在datetimepicker中显示该月份日期(windows应用程序)



如何做到这一点,



谢谢...

Hi All

How to validate datetime picker, here i want show date only in datetime picker based on month, the total 12 month is available on another ComboBox control, so which month user choose i want to show that month date only in datetimepicker(windows application)

how to do this,

Thanks...

推荐答案

您没有验证DateTimePicker - 而是使用 MinDate [ ^ ]和 MaxDate [ ^ ]属性限制它允许的范围,它将自行验证它们。



所以当你处理ComboBox更改了事件,将MinDate设置为当月的第一天,将MaxDate设置为该月的最后一天(这很简单:使用 DateTime.AddMonths [ ^ ]添加+1个月,然后 DateTime.AddDays [ ^ ]添加-1天,让你到达最后一天你想要的月份)
You don't "validate" a DateTimePicker - instead you use the MinDate[^] and MaxDate[^] properties to restrict the range that it permits and it will validate them itself.

So when you handle the ComboBox changed event, set the MinDate to teh first of that month, and the MaxDate to the last day of the month (Which is simple: Use DateTime.AddMonths[^] to add +1 month, then DateTime.AddDays[^] to add -1 days to get you to the last day of the month you want)


这篇关于如何验证Datetimepicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆