コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MonthViewMonth"/> class.
        /// </summary>
        /// <param name="monthView">The month view.</param>
        /// <param name="date">The date.</param>
        internal MonthViewMonth(MonthView monthView, DateTime date)
        {
            if (date.Day != 1)
            {
                date = new DateTime(date.Year, date.Month, 1);
            }


            _monthview = monthView;
            _date      = date;

            int preDays = (new int[] { 0, 1, 2, 3, 4, 5, 6 })[(int)date.DayOfWeek] - (int)MonthView.FirstDayOfWeek;

            days = new MonthViewDay[6 * 7];
            DateTime curDate = date.AddDays(-preDays);

            DayHeaders = new string[7];

            for (int i = 0; i < days.Length; i++)
            {
                days[i] = new MonthViewDay(this, curDate);

                if (i < 7)
                {
                    DayHeaders[i] = curDate.ToString(MonthView.DayNamesFormat).Substring(0, MonthView.DayNamesLength);
                }

                curDate = curDate.AddDays(1);
            }
        }
コード例 #2
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Control.MouseDown"/> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.MouseEventArgs"/> that contains the event data.</param>
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            Focus();

            _mouseDown = true;

            MonthViewDay day = HitTest(e.Location);

            if (day != null)
            {
                switch (SelectionMode)
                {
                case MonthViewSelection.Manual:
                case MonthViewSelection.Day:
                    SelectionEnd = _selectionStart = day.Date;
                    break;

                case MonthViewSelection.WorkWeek:
                    SelectWorkWeek(day.Date);
                    break;

                case MonthViewSelection.Week:
                    SelectWeek(day.Date);
                    break;

                case MonthViewSelection.Month:
                    SelectMonth(day.Date);
                    break;
                }
            }

            if (ForwardButtonSelected)
            {
                GoForward();
            }
            else if (BackwardButtonSelected)
            {
                GoBackward();
            }
        }
コード例 #3
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Control.MouseMove"/> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.MouseEventArgs"/> that contains the event data.</param>
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            if (_mouseDown)
            {
                MonthViewDay day = HitTest(e.Location);

                if (day != null && day != _lastHitted)
                {
                    switch (SelectionMode)
                    {
                    case MonthViewSelection.Manual:
                        if (day.Date > SelectionStart)
                        {
                            SelectionEnd = day.Date;
                        }
                        else
                        {
                            SelectionStart = day.Date;
                        }
                        break;

                    case MonthViewSelection.Day:
                        SelectionEnd = _selectionStart = day.Date;
                        break;

                    case MonthViewSelection.WorkWeek:
                        SelectWorkWeek(day.Date);
                        break;

                    case MonthViewSelection.Week:
                        SelectWeek(day.Date);
                        break;

                    case MonthViewSelection.Month:
                        SelectMonth(day.Date);
                        break;
                    }

                    _lastHitted = day;
                }
            }

            if (ForwardButtonBounds.Contains(e.Location))
            {
                SetForwardButtonSelected(true);
            }
            else if (ForwardButtonSelected)
            {
                SetForwardButtonSelected(false);
            }

            if (BackwardButtonBounds.Contains(e.Location))
            {
                SetBackwardButtonSelected(true);
            }
            else if (BackwardButtonSelected)
            {
                SetBackwardButtonSelected(false);
            }
        }