public void PrevMonth()
{
// Get the number of months to move
int move = _calendar.ScrollChange;
if (move == 0)
move = 1;
// Calculate the next set of months shown
DateTime prevMonth = _displayMonth.AddMonths(-move);
// We do not move the month if doing so moves it past the maximum date
if (prevMonth >= FirstDayOfMonth(_calendar.MinDate))
{
// Use the newly calculated month
_displayMonth = prevMonth;
DateTime lastDate = _displayMonth.AddMonths(_calendar.CalendarDimensions.Width *
_calendar.CalendarDimensions.Height);
// If the start of the selection is no longer visible
if (_calendar.SelectionStart >= lastDate)
{
// Find new selection dates
DateTime newSelStart = _calendar.SelectionStart.AddMonths(-move);
DateTime newSelEnd = _calendar.SelectionEnd.AddMonths(-move);
// Impose the min/max dates
if (newSelStart < _calendar.MinDate) newSelStart = _calendar.MinDate;
if (newSelEnd < _calendar.MinDate) newSelEnd = _calendar.MinDate;
// Shift selection backwards
_calendar.SetSelectionRange(newSelStart, newSelEnd);
}
_needPaintDelegate(this, new NeedLayoutEventArgs(true));
}
}