Limiting the dates within a C# win form DateTimePicker

前端 未结 5 1375
悲&欢浪女
悲&欢浪女 2020-12-11 22:33

Is it possible to limit which dates a user can select from a dateTimePicker on a C# winforms application?

The basic principle for me is this: I have a <

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-11 23:19

    You can set up the date restrictions in the following manner

    dateTimePicker1.MinDate = DateTime.Today.AddDays(-2);
    dateTimePicker1.MaxDate = DateTime.Today.AddDays(2);
    

    In these case only the 5 available dates would be selectable for the user and the rest is not available. You could set up these values in the selectedindex changed event for the combobox and restrict it on the basis of your requirement/logic.

提交回复
热议问题