Extended Calendar Control

Sep 30, 2009 at 6:19 AM

Hi,

Can you please highlight the code for the extended calendar control that you have developed, where you are incrementing the year and month separately.

Thanks
BKrishna

Coordinator
Sep 30, 2009 at 3:41 PM

In the ucCalendarExtended class there are 4 functions that control the Month and Year movement.  For the month it starts on line 164 and goes to line 200 in the btnMoveMonthLeft_MouseLeftButtonUp and btnMoveMonthRight_MouseLeftButtonUp events.  In these events I have a global index (_CurrentIndex) that keeps place of what the first month in the view is and also a varibale (MonthSpan) that determines how many months to move.  Then I call two functions MoveRight and MoveLeft that use a storyboard to animate the months movement.  For the year movement in the same class from lines 202 to 216 there are two events btnMoveYearLeft_MouseLeftButtonUp and btnMoveYearRight_MouseLeftButtonUp that increment/decrement an index variable (_ThisYear) that keeps track of the current year in view and then repopulates the calendar.

        #region btnMoveMonthLeft_MouseLeftButtonUp
        private void btnMoveMonthLeft_MouseLeftButtonUp(System.Object sender, RoutedEventArgs e)
        {
            if (!((_CurrentIndex - MonthSpan) < 0))
            {
                _CurrentIndex = _CurrentIndex - MonthSpan;
                MoveRight();
            }

            if (_CurrentIndex >= 10)
                MonthsInView = Enum.Parse(typeof(Enumerations.MonthsInYearLongDesc), _CurrentIndex.ToString(), false).ToString() + ", " + _ThisYear + " - " + Enum.Parse(typeof(Enumerations.MonthsInYearLongDesc), 12.ToString(), false).ToString() + ", " + _ThisYear;
            else
                MonthsInView = Enum.Parse(typeof(Enumerations.MonthsInYearLongDesc), _CurrentIndex.ToString(), false).ToString() + ", " + _ThisYear + " - " + Enum.Parse(typeof(Enumerations.MonthsInYearLongDesc), (_CurrentIndex + 2).ToString(), false).ToString() + ", " + _ThisYear;
        }
        #endregion
       #region btnMoveMonthRight_MouseLeftButtonUp
       private void btnMoveMonthRight_MouseLeftButtonUp(System.Object sender, RoutedEventArgs e)
        {
            if ((_CurrentIndex + MonthSpan) > 12)
            {
                this.LastLeft = 1;
                _CurrentIndex = 1;
                MoveRight();
            }
            else
            {
                _CurrentIndex = _CurrentIndex + MonthSpan;
                MoveLeft();
            }

            if (_CurrentIndex >= 10)
                MonthsInView = Enum.Parse(typeof(Enumerations.MonthsInYearLongDesc), _CurrentIndex.ToString(), false).ToString() + ", " + _ThisYear + " - " + Enum.Parse(typeof(Enumerations.MonthsInYearLongDesc), 12.ToString(), false).ToString() + ", " + _ThisYear;
            else
                MonthsInView = Enum.Parse(typeof(Enumerations.MonthsInYearLongDesc), _CurrentIndex.ToString(), false).ToString() + ", " + _ThisYear + " - " + Enum.Parse(typeof(Enumerations.MonthsInYearLongDesc), (_CurrentIndex + 2).ToString(), false).ToString() + ", " + _ThisYear;
        }
        #endregion 

        #region btnMoveYearLeft_MouseLeftButtonUp
        private void btnMoveYearLeft_MouseLeftButtonUp(System.Object sender, RoutedEventArgs e)
        {
            _ThisYear--;
            PopulateCalendar();
        }
        #endregion

        #region btnMoveYearRight_MouseLeftButtonUp
        private void btnMoveYearRight_MouseLeftButtonUp(System.Object sender, RoutedEventArgs e)
        {
            _ThisYear++;
            PopulateCalendar();
        }
        #endregion 
If you need any further instructions on this matter just let me know and I will be glad to help.  
If you give me a little information on what you are trying to accomplish with this then I can further 
know how to focus my awnswers to you.
Thanks,

Dixxieonmymind
Oct 1, 2009 at 5:54 AM

Hi,

Thanks again for the reply. I will go through your code, in case I get stuck somewhere I will ask for your help.

On what I am trying to accomplish is, I am thinking of having a date control popup when the datepicker control (or a plain textbox) is clicked. The date control (Calendar) will have month displayed on the right of the calendar with a up and down arrow to move between months, the year will be displayed on top which will have a next and prev arrows to move between years and in the center the days (numeric dates) will be displayed. I think your code here will surely give me a way to do this. Thanks