[英]How to restrict user to select only current month dates in datetimepicker control?
我希望用戶僅選擇當前月份的日期,但我不知道應該在min和max date屬性中添加什么。
是否有“當前月份”之類的屬性?
是的,您可以使用屬性MinDate和MaxDate並設置可以在控件中選擇的最小和最大日期。
var currentYear = DateTime.Now.Year;
var currentMonth = DateTime.Now.Month;
int firstDayInCurrentMonth = 1;
int lastDayInCurrentMonth = DateTime.DaysInMonth(currentYear, currentMonth);
dateTimePicker.MinDate = new DateTime(currentYear, currentMonth, firstDayInCurrentMonth);
dateTimePicker.MaxDate = new DateTime(currentYear, currentMonth, lastDayInCurrentMonth);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.