在C#赢形式的DateTimePicker限制的日期形式、日期、DateTimePicker

2023-09-02 10:53:35 作者:此人已疯

是否有可能限制其历史,用户可以从的DateTimePicker 在C#的WinForms应用程序中选择?

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

我的基本原理是这样的:我有一个组合框有5个项目在它的基础上,该项目的用户选择,我想限制其历史的用户然后可以选择,具有不可用的日期显示为灰色。

The basic principle for me is this: I have a comboBox with 5 items in it, based on which item the user selects I would like to limit which dates the user can then select from, having the unavailable dates grayed out.

这可能吗?

推荐答案

使用的 为MinDate 和的 的maxDate 属性。

Use the MinDate and MaxDate properties.

dateTimePicker.MinDate = DateTime.Now;
dateTimePicker.MaxDate = DateTime.Now.AddDays(15);

(渲染在法国的Windows 7)

(render on a french Windows 7)