DateTimePicker限制按年份选择下拉

本文关键字:选择 DateTimePicker | 更新日期: 2023-09-27 18:11:51

是否可以在日历下拉时仅通过年份选择限制DateTimePicker ?

DateTimePicker限制按年份选择下拉

按以下步骤操作:

  • 像这样改变DateTimePickerFormatCustom的属性:

    dateTimePicker1.Format = DateTimePickerFormat.Custom;
    
  • CustomFormat更改为yyyy,如下所示:

    dateTimePicker1.CustomFormat = "yyyy";
    
  • ShowUpDown属性设置为truefalse,如下所示:

    dateTimePicker1.ShowUpDown = true;