月历-禁用天数 [英] MonthCalendar - Disable days
问题描述
我正在使用Visual Studio C#编写应用程序,并且正在使用Windows窗体.我需要用户能够从特定范围中选择日期(为此,我正在使用MinDate
和MaxDate
),并且只能选择一周中的某些天.例如,我想禁用 Mondays .我正在使用MonthCalendar
,但是我还没有找到禁用星期几的方法...可能吗?
I'm doing an application in C# with Visual Studio, and I'm using Windows Forms. I need the user to be able to select a date from a specific range (for this I'm using MinDate
and MaxDate
), and only some days of the week. For example, I want to disable Mondays. I'm using MonthCalendar
, but I haven't found a way to disable days of the week... Is it possible?
推荐答案
您不能阻止用户在日历上选择日期.毫无疑问,抱怨并提供了更好的选择:
You can't stop the user from picking a date on the calendar. No trouble however complaining and offering a better choice:
private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e) {
if (e.Start.DayOfWeek == DayOfWeek.Monday) {
MessageBox.Show("I hate mondays");
monthCalendar1.SelectionStart = e.Start.AddDays(1);
}
}
使用BoldedDates
属性可以使有效选择更加明显.
Use the BoldedDates
property to make valid selections more obvious.
这篇关于月历-禁用天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!