问题
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?
回答1:
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);
}
}
Use the BoldedDates
property to make valid selections more obvious.
回答2:
The short answer is no. You could add a validation event that would check which day of the week was selected.
The built-in controls only offer so much options out of the box. To disable certain days of the week you will need to write your own control.
Once you start writing your custom control and you become stuck, you can post your code and question here and people will help.
来源:https://stackoverflow.com/questions/19214940/monthcalendar-disable-days