예제 #1
0
        /// <summary>
        /// Draws the background of the footer.
        /// </summary>
        /// <param name="g">The <see cref="Graphics"/> object used to draw.</param>
        /// <param name="footerBounds">The bounds of the footer.</param>
        /// <param name="active">true if the footer is in mouse over state, otherwise false.</param>
        public virtual void DrawFooterBackground(Graphics g, Rectangle footerBounds, bool active)
        {
            if (!CheckParams(g, footerBounds))
            {
                return;
            }

            MonthCalendarColorTable colors = this.ColorTable;

            if (active)
            {
                FillBackground(
                    g,
                    footerBounds,
                    colors.FooterActiveGradientBegin,
                    colors.FooterActiveGradientEnd,
                    colors.FooterActiveGradientMode);
            }
            else
            {
                FillBackground(
                    g,
                    footerBounds,
                    colors.FooterGradientBegin,
                    colors.FooterGradientEnd,
                    colors.FooterGradientMode);
            }
        }
        /// <summary>
        /// Draws a day in the month body of the calendar control.
        /// </summary>
        /// <param name="g">The <see cref="Graphics"/> object used to draw.</param>
        /// <param name="day">The <see cref="MonthCalendarDay"/> to draw.</param>
        public override void DrawDay(Graphics g, MonthCalendarDay day)
        {
            if (!CheckParams(g, day.Bounds))
            {
                return;
            }

            // get color table
            MonthCalendarColorTable colors = this.ColorTable;

            // get the bounds of the day
            Rectangle rect = day.Bounds;

            var boldDate = this.monthCal.BoldedDatesCollection.Find(d => d.Value.Date == day.Date.Date);

            // if day is selected or in mouse over state
            if (day.MouseOver)
            {
                FillBackground(
                    g,
                    rect,
                    colors.DayActiveGradientBegin,
                    colors.DayActiveGradientEnd,
                    colors.DayActiveGradientMode);
            }
            else if (day.Selected)
            {
                this.FillBackgroundInternal(
                    g,
                    rect,
                    colors.DaySelectedGradientBegin,
                    colors.DaySelectedGradientEnd,
                    colors.DaySelectedGradientMode);
            }
            else if (!boldDate.IsEmpty && boldDate.Category.BackColorStart != Color.Empty && boldDate.Category.BackColorStart != Color.Transparent)
            {
                FillBackground(
                    g,
                    rect,
                    boldDate.Category.BackColorStart,
                    boldDate.Category.BackColorEnd.IsEmpty || boldDate.Category.BackColorEnd == Color.Transparent ? boldDate.Category.BackColorStart : boldDate.Category.BackColorEnd,
                    boldDate.Category.GradientMode);
            }

            // get bolded dates
            List <DateTime> boldedDates = this.monthCal.GetBoldedDates();

            bool bold = boldedDates.Contains(day.Date) || !boldDate.IsEmpty;

            // draw the day
            using (StringFormat format = GetStringAlignment(this.monthCal.DayTextAlignment))
            {
                Color textColor = bold ? (boldDate.IsEmpty || boldDate.Category.ForeColor == Color.Empty || boldDate.Category.ForeColor == Color.Transparent ? colors.DayTextBold : boldDate.Category.ForeColor)
               : (day.Selected ? colors.DaySelectedText
               : (day.MouseOver ? colors.DayActiveText
               : (day.TrailingDate ? colors.DayTrailingText
               : colors.DayText)));

                using (SolidBrush brush = new SolidBrush(textColor))
                {
                    using (Font font = new Font(
                               this.monthCal.Font.FontFamily,
                               this.monthCal.Font.SizeInPoints,
                               FontStyle.Bold))
                    {
                        // adjust width
                        Rectangle textRect = day.Bounds;
                        textRect.Width -= 2;

                        // determine if to use bold font
                        //bool useBoldFont = day.Date == DateTime.Today || bold;
                        bool useBoldFont = bold;

                        var calDate = new MonthCalendarDate(monthCal.CultureCalendar, day.Date);

                        string dayString = this.monthCal.UseNativeDigits
                                        ? DateMethods.GetNativeNumberString(calDate.Day, this.monthCal.Culture.NumberFormat.NativeDigits, false)
                                        : calDate.Day.ToString(this.monthCal.Culture);

                        //if (!day.TrailingDate)
                        //{

                        if (this.monthCal.Enabled)
                        {
                            g.DrawString(
                                dayString,
                                (useBoldFont ? font : this.monthCal.Font),
                                brush,
                                textRect,
                                format);
                        }
                        else
                        {
                            ControlPaint.DrawStringDisabled(
                                g,
                                dayString,
                                (useBoldFont ? font : this.monthCal.Font),
                                Color.Transparent,
                                textRect,
                                format);
                        }
                        //}
                    }
                }
            }

            // if today, draw border
            //if (day.Date == DateTime.Today)
            //{
            //   rect.Height -= 1;
            //   rect.Width -= 2;
            //   Color borderColor = day.Selected ? colors.DaySelectedTodayCircleBorder
            //      : (day.MouseOver ? colors.DayActiveTodayCircleBorder : colors.DayTodayCircleBorder);

            //   using (Pen p = new Pen(borderColor))
            //   {
            //      g.DrawRectangle(p, rect);

            //      rect.Offset(1, 0);

            //      g.DrawRectangle(p, rect);
            //   }
            //}
        }
        /// <summary>
        /// Draws the header of a <see cref="MonthCalendarMonth"/>.
        /// </summary>
        /// <param name="g">The <see cref="Graphics"/> object used to draw.</param>
        /// <param name="calMonth">The <see cref="MonthCalendarMonth"/> to draw the header for.</param>
        /// <param name="state">The <see cref="MonthCalendarHeaderState"/>.</param>
        public override void DrawMonthHeader(
            Graphics g,
            MonthCalendarMonth calMonth,
            MonthCalendarHeaderState state)
        {
            if (calMonth == null || !CheckParams(g, calMonth.TitleBounds))
            {
                return;
            }

            // get title bounds
            Rectangle rect = calMonth.TitleBounds;

            MonthCalendarDate date         = new MonthCalendarDate(monthCal.CultureCalendar, calMonth.Date);
            MonthCalendarDate firstVisible = new MonthCalendarDate(monthCal.CultureCalendar, calMonth.FirstVisibleDate);

            string month;
            int    year;

            // gets the month name for the month the MonthCalendarMonth represents and the year string
            if (firstVisible.Era != date.Era)
            {
                month = this.monthCal.FormatProvider.GetMonthName(firstVisible.Year, firstVisible.Month);
                year  = firstVisible.Year;
            }
            else
            {
                month = this.monthCal.FormatProvider.GetMonthName(date.Year, date.Month);
                year  = date.Year;
            }

            string yearString = this.monthCal.UseNativeDigits
            ? DateMethods.GetNativeNumberString(year, this.monthCal.Culture.NumberFormat.NativeDigits, false)
            : year.ToString(CultureInfo.CurrentUICulture);

            // get used font
            Font headerFont = this.monthCal.HeaderFont;

            // create bold font
            Font boldFont = new Font(headerFont.FontFamily, headerFont.SizeInPoints, FontStyle.Bold);

            // measure sizes
            SizeF monthSize = g.MeasureString(month, boldFont);

            SizeF yearSize = g.MeasureString(yearString, boldFont);

            float maxHeight = Math.Max(monthSize.Height, yearSize.Height);

            // calculates the width and the starting position of the arrows
            int width       = (int)monthSize.Width + (int)yearSize.Width + 7;
            int arrowLeftX  = rect.X + 6;
            int arrowRightX = rect.Right - 6;
            int arrowY      = rect.Y + (rect.Height / 2) - 4;

            int x = Math.Max(0, rect.X + (rect.Width / 2) + 1 - (width / 2));
            int y = Math.Max(
                0,
                rect.Y + (rect.Height / 2) + 1 - (((int)maxHeight + 1) / 2));

            // set the title month name bounds
            calMonth.TitleMonthBounds = new Rectangle(
                x,
                y,
                (int)monthSize.Width + 1,
                (int)maxHeight + 1);

            // set the title year bounds
            calMonth.TitleYearBounds = new Rectangle(
                x + calMonth.TitleMonthBounds.Width + 7,
                y,
                (int)yearSize.Width + 1,
                (int)maxHeight + 1);

            // generate points for the left and right arrow
            Point[] arrowLeft = new[]
            {
                new Point(arrowLeftX, arrowY + 4),
                new Point(arrowLeftX + 4, arrowY),
                new Point(arrowLeftX + 4, arrowY + 8),
                new Point(arrowLeftX, arrowY + 4)
            };

            Point[] arrowRight = new[]
            {
                new Point(arrowRightX, arrowY + 4),
                new Point(arrowRightX - 4, arrowY),
                new Point(arrowRightX - 4, arrowY + 8),
                new Point(arrowRightX, arrowY + 4)
            };

            // get color table
            MonthCalendarColorTable colorTable = this.ColorTable;

            // get brushes for normal, mouse over and selected state
            using (SolidBrush brush = new SolidBrush(colorTable.HeaderText),
                   brushOver = new SolidBrush(colorTable.HeaderActiveText),
                   brushSelected = new SolidBrush(colorTable.HeaderSelectedText))
            {
                // get title month name and year bounds
                Rectangle monthRect = calMonth.TitleMonthBounds;
                Rectangle yearRect  = calMonth.TitleYearBounds;

                // set used fonts
                Font monthFont = headerFont;
                Font yearFont  = headerFont;

                // set used brushes
                SolidBrush monthBrush = brush, yearBrush = brush;

                // adjust brush and font if year selected
                if (state == MonthCalendarHeaderState.YearSelected)
                {
                    yearBrush       = brushSelected;
                    yearFont        = boldFont;
                    yearRect.Width += 4;
                }
                else if (state == MonthCalendarHeaderState.YearActive)
                {
                    // adjust brush if mouse over year
                    yearBrush = brushOver;
                }

                // adjust brush and font if month name is selected
                if (state == MonthCalendarHeaderState.MonthNameSelected)
                {
                    monthBrush       = brushSelected;
                    monthFont        = boldFont;
                    monthRect.Width += 4;
                }
                else if (state == MonthCalendarHeaderState.MonthNameActive)
                {
                    // adjust brush if mouse over month name
                    monthBrush = brushOver;
                }

                // draws the month name and year string
                g.DrawString(month, monthFont, monthBrush, monthRect);
                g.DrawString(yearString, yearFont, yearBrush, yearRect);
            }

            boldFont.Dispose();

            // if left arrow has to be drawn
            //if (calMonth.DrawLeftButton)
            //{
            //   // get arrow color
            //   Color arrowColor = this.monthCal.LeftButtonState == ButtonState.Normal ?
            //      GetGrayColor(this.monthCal.Enabled, colorTable.HeaderArrow) : colorTable.HeaderActiveArrow;

            //   // set left arrow rect
            //   this.monthCal.SetLeftArrowRect(new Rectangle(rect.X, rect.Y, 15, rect.Height));

            //   // draw left arrow
            //   using (GraphicsPath path = new GraphicsPath())
            //   {
            //      path.AddLines(arrowLeft);

            //      using (SolidBrush brush = new SolidBrush(arrowColor))
            //      {
            //         g.FillPath(brush, path);
            //      }

            //      using (Pen p = new Pen(arrowColor))
            //      {
            //         g.DrawPath(p, path);
            //      }
            //   }
            //}

            // if right arrow has to be drawn
            //   if (calMonth.DrawRightButton)
            //   {
            //      // get arrow color
            //      Color arrowColor = this.monthCal.RightButtonState == ButtonState.Normal ?
            //         GetGrayColor(this.monthCal.Enabled, colorTable.HeaderArrow) : colorTable.HeaderActiveArrow;

            //      // set right arrow rect
            //      this.monthCal.SetRightArrowRect(new Rectangle(rect.Right - 15, rect.Y, 15, rect.Height));

            //      // draw arrow
            //      using (GraphicsPath path = new GraphicsPath())
            //      {
            //         path.AddLines(arrowRight);

            //         using (SolidBrush brush = new SolidBrush(arrowColor))
            //         {
            //            g.FillPath(brush, path);
            //         }

            //         using (Pen p = new Pen(arrowColor))
            //         {
            //            g.DrawPath(p, path);
            //         }
            //      }
            //   }
        }
예제 #4
0
      /// <summary>
      /// Returns whether the property <see cref="ColorTable"/> should be serialized.
      /// </summary>
      /// <returns>true or false.</returns>
      /// <remarks>Only used by the designer.</remarks>
      internal bool ShouldSerializeColorTable()
      {
         MonthCalendarColorTable table = new MonthCalendarColorTable();
         MonthCalendarColorTable currentTable = this.ColorTable;

         return table.BackgroundGradientBegin != currentTable.BackgroundGradientBegin
            || table.BackgroundGradientEnd != currentTable.BackgroundGradientEnd
            || table.BackgroundGradientMode != currentTable.BackgroundGradientMode
            || table.Border != currentTable.Border
            || table.DayActiveGradientBegin != currentTable.DayActiveGradientBegin
            || table.DayActiveGradientEnd != currentTable.DayActiveGradientEnd
            || table.DayActiveGradientMode != currentTable.DayActiveGradientMode
            || table.DayActiveText != currentTable.DayActiveText
            || table.DayActiveTodayCircleBorder != currentTable.DayActiveTodayCircleBorder
            || table.DayHeaderGradientBegin != currentTable.DayHeaderGradientBegin
            || table.DayHeaderGradientEnd != currentTable.DayHeaderGradientEnd
            || table.DayHeaderGradientMode != currentTable.DayHeaderGradientMode
            || table.DayHeaderText != currentTable.DayHeaderText
            || table.DaySelectedGradientBegin != currentTable.DaySelectedGradientBegin
            || table.DaySelectedGradientEnd != currentTable.DaySelectedGradientEnd
            || table.DaySelectedGradientMode != currentTable.DaySelectedGradientMode
            || table.DaySelectedText != currentTable.DaySelectedText
            || table.DaySelectedTodayCircleBorder != currentTable.DaySelectedTodayCircleBorder
            || table.DayText != currentTable.DayText
            || table.DayTextBold != currentTable.DayTextBold
            || table.DayTodayCircleBorder != currentTable.DayTodayCircleBorder
            || table.DayTrailingText != currentTable.DayTrailingText
            || table.FooterActiveGradientBegin != currentTable.FooterActiveGradientBegin
            || table.FooterActiveGradientEnd != currentTable.FooterActiveGradientEnd
            || table.FooterActiveGradientMode != currentTable.FooterActiveGradientMode
            || table.FooterActiveText != currentTable.FooterActiveText
            || table.FooterGradientBegin != currentTable.FooterGradientBegin
            || table.FooterGradientEnd != currentTable.FooterGradientEnd
            || table.FooterGradientMode != currentTable.FooterGradientMode
            || table.FooterText != currentTable.FooterText
            || table.FooterTodayCircleBorder != currentTable.FooterTodayCircleBorder
            || table.HeaderActiveArrow != currentTable.HeaderActiveArrow
            || table.HeaderActiveGradientBegin != currentTable.HeaderActiveGradientBegin
            || table.HeaderActiveGradientEnd != currentTable.HeaderActiveGradientEnd
            || table.HeaderActiveGradientMode != currentTable.HeaderActiveGradientMode
            || table.HeaderActiveText != currentTable.HeaderActiveText
            || table.HeaderArrow != currentTable.HeaderArrow
            || table.HeaderGradientBegin != currentTable.HeaderGradientBegin
            || table.HeaderGradientEnd != currentTable.HeaderGradientEnd
            || table.HeaderGradientMode != currentTable.HeaderGradientMode
            || table.HeaderSelectedText != currentTable.HeaderSelectedText
            || table.HeaderText != currentTable.HeaderText
            || table.MonthBodyGradientBegin != currentTable.MonthBodyGradientBegin
            || table.MonthBodyGradientEnd != currentTable.MonthBodyGradientEnd
            || table.MonthBodyGradientMode != currentTable.MonthBodyGradientMode
            || table.MonthSeparator != currentTable.MonthSeparator
            || table.WeekHeaderGradientBegin != currentTable.WeekHeaderGradientBegin
            || table.WeekHeaderGradientEnd != currentTable.WeekHeaderGradientEnd
            || table.WeekHeaderGradientMode != currentTable.WeekHeaderGradientMode
            || table.WeekHeaderText != currentTable.WeekHeaderText;
      }