Пример #1
0
 /// <summary>
 /// Returns copy of the item.
 /// </summary>
 public override BaseItem Copy()
 {
     SingleMonthCalendar objCopy = new SingleMonthCalendar();
     this.CopyToItem(objCopy);
     return objCopy;
 }
Пример #2
0
 private void ApplyCommonProperties(SingleMonthCalendar m)
 {
     m.DisplayMonth = DateTime.Today;
     m.DayClickAutoClosePopup = _DayClickAutoClosePopup;
     m.YearSelectionEnabled = _YearSelectionEnabled;
 }
Пример #3
0
        public override void RecalcSize()
        {
            SingleMonthCalendar m = this.SubItems[0] as SingleMonthCalendar;
            if (m == null)
                return;
            _UpdatingSelectedDate = true;
            int index = 1;
            int monthsVisible = 1;
            DateTime currentMonth = _DisplayMonth;
            Size newSize = Size.Empty;
            bool disposeStyle = false;
            ElementStyle backStyle = GetRenderBackgroundStyle(out disposeStyle);
            Rectangle bounds = ElementStyleLayout.GetInnerRect(backStyle, this.Bounds);
            SingleMonthCalendar firstCalendarMonth = m;
            SingleMonthCalendar lastCalendarMonth = null;
            m.TrailingDaysVisible = false;
            m.DisplayMonth = currentMonth;
            m.LeftInternal = bounds.X;
            m.TopInternal = bounds.Y;
            m.RecalcSize();
            m.Displayed = true;
            m.MouseSelectionEnabled = !_MultiSelect;
            if (!_MultiSelect)
                UpdateSelectedDates(m);
            else
                m.SelectedDate = DateTime.MinValue;
            newSize = m.Size;
            Size defaultSize = m.Size;

            Point location = bounds.Location;
            location.X += defaultSize.Width + _Spacing.Width;
            int lineWidth = newSize.Width;
            Size columnRows = new Size(1, 1);
            while (location.Y < bounds.Bottom && _CalendarDimensions.IsEmpty || !_CalendarDimensions.IsEmpty && _CalendarDimensions.Height + 1 > columnRows.Height)
            {
                if (index < this.SubItems.Count && this.SubItems[index] == _BottomContainer)
                    index++;

                if (location.X + defaultSize.Width > bounds.Right && _CalendarDimensions.IsEmpty || !_CalendarDimensions.IsEmpty && columnRows.Width >= _CalendarDimensions.Width)
                {
                    location.Y += defaultSize.Height + _Spacing.Height;
                    location.X = bounds.X;

                    if (lineWidth > newSize.Width)
                        newSize.Width = lineWidth - (columnRows.Height > 1 ? _Spacing.Width : 0);
                    lineWidth = 0;
                    columnRows.Height++;
                    columnRows.Width = 0;
                    if (location.Y + defaultSize.Height > bounds.Bottom && _CalendarDimensions.IsEmpty ||
                        !_CalendarDimensions.IsEmpty && columnRows.Height > _CalendarDimensions.Height)
                        break;
                    newSize.Height += defaultSize.Height + _Spacing.Height;
                }

                if (this.SubItems.Count == index)
                {
                    m = new SingleMonthCalendar();
                    m.DaySize = firstCalendarMonth.DaySize;
                    m.Visible = true;
                    m.Displayed = true;
                    m.TrailingDaysVisible = false;
                    m.HeaderNavigationEnabled = false;
                    m.PaintLabel += new DayPaintEventHandler(InternalPaintLabel);
                    m.LabelMouseDown += new System.Windows.Forms.MouseEventHandler(InternalLabelMouseDown);
                    m.LabelMouseEnter += new EventHandler(InternalLabelMouseEnter);
                    m.LabelMouseHover += new EventHandler(InternalLabelMouseHover);
                    m.LabelMouseLeave += new EventHandler(InternalLabelMouseLeave);
                    m.LabelMouseMove += new System.Windows.Forms.MouseEventHandler(InternalLabelMouseMove);
                    m.LabelMouseUp += new System.Windows.Forms.MouseEventHandler(InternalLabelMouseUp);
                    m.NavigationBackgroundStyle.ApplyStyle(firstCalendarMonth.NavigationBackgroundStyle);
                    m.DateChanged += new EventHandler(SingleMonthSelectedDateChanged);
                    ApplyCommonProperties(m);
                    if (this.SubItems[this.SubItems.Count - 1] == _BottomContainer)
                        this.SubItems.Insert(this.SubItems.Count - 1, m);
                    else
                        this.SubItems.Add(m);
                }
                else
                    m = (SingleMonthCalendar)this.SubItems[index];
                m.TwoLetterDayName = this.TwoLetterDayName;
                m.MinDate = this.MinDate;
                m.MaxDate = this.MaxDate;
                m.WeekOfYearRule = this.WeekOfYearRule;
                m.WeekendDaysSelectable = this.WeekendDaysSelectable;
                m.TodayDate = this.TodayDate;
                m.ShowTodayMarker = this.ShowTodayMarker;
                m.ShowWeekNumbers = this.ShowWeekNumbers;
                m.FirstDayOfWeek = this.FirstDayOfWeek;
                m.DayNames = this.DayNames;
                m.TrailingDaysVisible = false;
                m.MouseSelectionEnabled = !_MultiSelect;
                if (!_MultiSelect)
                    UpdateSelectedDates(m);
                else
                    m.SelectedDate = DateTime.MinValue;

                index++;
                monthsVisible++;
                columnRows.Width++;

                lineWidth += _Spacing.Width;
                m.TopInternal = location.Y;
                m.LeftInternal = location.X;
                currentMonth = currentMonth.AddMonths(1);
                m.DisplayMonth = currentMonth;
                m.RecalcSize();
                lastCalendarMonth = m;
                lineWidth += m.WidthInternal;
                location.X += m.WidthInternal + _Spacing.Width;
            }

            for (int i = index; i < this.SubItems.Count; i++)
            {
                m = this.SubItems[i] as SingleMonthCalendar;
                if (m != null)
                {
                    m.PaintLabel -= new DayPaintEventHandler(InternalPaintLabel);
                    m.LabelMouseDown -= new System.Windows.Forms.MouseEventHandler(InternalLabelMouseDown);
                    m.LabelMouseEnter -= new EventHandler(InternalLabelMouseEnter);
                    m.LabelMouseHover -= new EventHandler(InternalLabelMouseHover);
                    m.LabelMouseLeave -= new EventHandler(InternalLabelMouseLeave);
                    m.LabelMouseMove -= new System.Windows.Forms.MouseEventHandler(InternalLabelMouseMove);
                    m.LabelMouseUp -= new System.Windows.Forms.MouseEventHandler(InternalLabelMouseUp);
                    m.DateChanged -= new EventHandler(SingleMonthSelectedDateChanged);
                }
                if (this.SubItems[i] != _BottomContainer)
                    this.SubItems.Remove(i);
            }

            // Bottom container
            if (_BottomContainerName != null && _BottomContainer.Visible)
            {
                ItemContainer cont = _BottomContainer;
                cont.Displayed = true;
                cont.TopInternal = location.Y;
                cont.LeftInternal = location.X;
                cont.WidthInternal = newSize.Width;
                cont.RecalcSize();
                cont.WidthInternal = newSize.Width;
                newSize.Height += cont.HeightInternal + _Spacing.Height;
            }

            newSize.Width += ElementStyleLayout.HorizontalStyleWhiteSpace(backStyle);
            newSize.Height += ElementStyleLayout.VerticalStyleWhiteSpace(backStyle);

            if (this.SubItems.Count == 1 || this.SubItems.Count == 2 && _BottomContainer != null)
            {
                firstCalendarMonth._TrailingDaysAfterVisible = true;
                firstCalendarMonth._TrailingDaysBeforeVisible = true;
                firstCalendarMonth.TrailingDaysVisible = true;
            }
            else
            {
                firstCalendarMonth._TrailingDaysAfterVisible = false;
                firstCalendarMonth._TrailingDaysBeforeVisible = true;
                firstCalendarMonth.TrailingDaysVisible = true;
                lastCalendarMonth._TrailingDaysAfterVisible = true;
                lastCalendarMonth._TrailingDaysBeforeVisible = false;
                lastCalendarMonth.TrailingDaysVisible = true;
            }
            firstCalendarMonth.NavigationMonthsAheadVisibility = monthsVisible;
            this.Bounds = new Rectangle(this.Bounds.Location, newSize);
            base.RecalcSize();
            ApplySelection();
            OnMonthChanged(new EventArgs());
            _UpdatingSelectedDate = false;

            if(disposeStyle) backStyle.Dispose();
        }
Пример #4
0
 private void UpdateSelectedDates(SingleMonthCalendar m)
 {
     if (m.DisplayMonth.Month == _SelectedDate.Month && m.DisplayMonth.Year == _SelectedDate.Year ||
         m.TrailingDaysVisible && m.GetDayLabel(_SelectedDate) != null)
         m.SelectedDate = _SelectedDate;
     else if (m.SelectedDate != DateTime.MinValue)
         m.SelectedDate = DateTime.MinValue;
 }
Пример #5
0
        /// <summary>
        /// Initializes a new instance of the MonthCalendarItem class.
        /// </summary>
        public MonthCalendarItem()
        {
            _Colors.Parent = this;

            // At least one month is always visible
            SingleMonthCalendar m = new SingleMonthCalendar();
            m.MonthChanging += new EventHandler(FirstCalendarMonthChanging);
            m.MonthChanged += new EventHandler(FirstCalendarMonthChanged);
            m.PaintLabel += new DayPaintEventHandler(InternalPaintLabel);
            m.LabelMouseDown += new System.Windows.Forms.MouseEventHandler(InternalLabelMouseDown);
            m.LabelMouseEnter += new EventHandler(InternalLabelMouseEnter);
            m.LabelMouseHover += new EventHandler(InternalLabelMouseHover);
            m.LabelMouseLeave += new EventHandler(InternalLabelMouseLeave);
            m.LabelMouseMove += new System.Windows.Forms.MouseEventHandler(InternalLabelMouseMove);
            m.LabelMouseUp += new System.Windows.Forms.MouseEventHandler(InternalLabelMouseUp);
            m.NavigationBackgroundStyle.StyleChanged += new EventHandler(FirstCalendarBackStyleChanged);
            m.DateChanged += new EventHandler(SingleMonthSelectedDateChanged);
            this.SubItems.Add(m);

            _BottomContainer = new ItemContainer();
            _BottomContainer.AutoCollapseOnClick = false;
            _BottomContainer.Visible = false;
            _BottomContainer.HorizontalItemAlignment = eHorizontalItemsAlignment.Center;
            _BottomContainer.LayoutOrientation = eOrientation.Horizontal;
            _BottomContainer.ItemSpacing = 6;
            _BottomContainer.Name = _BottomContainerName;

            _TodayButton = CreateTodayButton();
            _BottomContainer.SubItems.Add(_TodayButton);
            _ClearButton = CreateClearButton();
            _BottomContainer.SubItems.Add(_ClearButton);

            this.SubItems.Add(_BottomContainer);

            UpdateSystemButtonsVisibility();
        }