ComponentFactory.Krypton.Toolkit.ViewLayoutMonths.NextMonth C# (CSharp) Method

NextMonth() public method

Move to the next month.
public NextMonth ( ) : void
return void
        public void NextMonth()
        {
            // Get the number of months to move
            int move = _calendar.ScrollChange;
            if (move == 0)
                move = 1;

            // Calculate the next set of months shown
            DateTime nextMonth = _displayMonth.AddMonths(move);
            DateTime lastDate = nextMonth.AddMonths(_calendar.CalendarDimensions.Width *
                                                    _calendar.CalendarDimensions.Height);

            DateTime ld = lastDate.AddDays(-1);
            DateTime ldofm = LastDayOfMonth(_calendar.MaxDate);

            // We do not move the month if doing so moves it past the maximum date
            if (lastDate.AddDays(-1) <= LastDayOfMonth(_calendar.MaxDate))
            {
                // Use the newly calculated month
                _displayMonth = nextMonth;

                // If the end of the selection is no longer visible
                if (_calendar.SelectionEnd < _displayMonth)
                {
                    // Find new selection dates
                    DateTime newSelStart = _calendar.SelectionStart.AddMonths(move);
                    DateTime newSelEnd = _calendar.SelectionEnd.AddMonths(move);

                    // Impose the min/max dates
                    if (newSelStart > _calendar.MaxDate) newSelStart = _calendar.MaxDate;
                    if (newSelEnd > _calendar.MaxDate) newSelEnd = _calendar.MaxDate;

                    // Shift selection onwards
                    _calendar.SetSelectionRange(newSelStart, newSelEnd);
                }

                _needPaintDelegate(this, new NeedLayoutEventArgs(true));
            }
        }

Usage Example

 private void OnNextMonth(object sender, EventArgs e)
 {
     _months.NextMonth();
 }