Using% native%, the most you can do is check if the selected date is a Saturday or a Sunday, something like this:
private void monthCalendar_DateChanged(object sender, DateRangeEventArgs e)
{
// se a data selecionada for diferente de domingo e sábado
if (e.Start.DayOfWeek != DayOfWeek.Sunday && e.Start.DayOfWeek != DayOfWeek.Saturday)
{
// seleciona o primeiro domingo anterior a data selecionada
monthCalendar.SelectionStart = monthCalendar.SelectionStart
.AddDays(-(Double)e.Start.DayOfWeek);
monthCalendar.SelectionEnd = monthCalendar.SelectionStart;
// exibe mensagem de data fora do intervalo
MessageBox.Show("Você não pode selecionar nenhuma data entre segunda e sexta.",
"Atenção", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
If this does not really suit you, you can try using one of the custom controls below:
In MonthCalendar
, you have event MonthCalendar 1
, where you can prevent the days of the week from being created.
private void monthCalendar1_MonthDayRender(object sender, MonthCalendar.MonthDayRenderEventArgs e)
{
if (e.WeekDay != DayOfWeek.Sunday && e.WeekDay != DayOfWeek.Saturday)
{
e.OwnerDraw = true;
}
}
Something that may also be of interest to you in this control is the MonthDayRender
property that is inside the ShowTrailingsDays
property, this property hides the days before and after the current calendar month.
In%%, you have event MonthDays
, which can also prevent weekdays from being created.
private void monthCalendar2_DayRender(object sender, Pabo.Calendar.DayRenderEventArgs e)
{
if (e.Date.DayOfWeek != DayOfWeek.Sunday && e.Date.DayOfWeek != DayOfWeek.Saturday)
{
e.OwnerDraw = true;
}
}
It seems that MonthCalendar 2
is more complete and enables more customization.
Note: I never got to use either of the two components, I found them after doing some research on the internet.