MonthCalendar - Disable days

大憨熊 提交于 2019-12-08 08:56:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!