我正在为.NET 2 WinForm查找月份选择器控件。
使用 DateTimePicker . 你可以使用 custom format 只允许指定月份和年份。
DateTimePicker
例子:
DateTimePicker dateTimePicker1 = new DateTimePicker(); dateTimePicker1.Format = DateTimePickerFormat.Custom; dateTimePicker1.CustomFormat = "MM yyyy"; dateTimePicker1.ShowUpDown = true; // to prevent the calendar from being displayed
见 this MSDN article 更多信息。
编辑: 若要阻止显示日历,请设置 ShowUpDown 属性上 日期输入框 到 true . 这将阻止显示日历和 CustomFormat )允许您使用向上/向下按钮仅设置月份和年份。
ShowUpDown
日期输入框
true
CustomFormat