Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MonthCalendarWeek"/> class.
 /// </summary>
 /// <param name="month">The corresponding <see cref="MonthCalendarMonth"/> that contains this instance.</param>
 /// <param name="weekNumber">The corresponding week number.</param>
 /// <param name="start">The start date of the week.</param>
 /// <param name="end">The end date of the week.</param>
 public MonthCalendarWeek(MonthCalendarMonth month, int weekNumber, DateTime start, DateTime end)
 {
     this.WeekNumber = weekNumber;
     this.Start      = start;
     this.End        = end;
     this.Month      = month;
 }
Esempio n. 2
0
        /// <summary>
        /// Draws the title background for the specified <paramref name="month"/>.
        /// </summary>
        /// <param name="g">The <see cref="Graphics"/> object used to draw.</param>
        /// <param name="month">The <see cref="MonthCalendarMonth"/> to draw the title for.</param>
        /// <param name="state">The <see cref="MonthCalendarHeaderState"/> of the title.</param>
        public virtual void DrawTitleBackground(Graphics g, MonthCalendarMonth month, MonthCalendarHeaderState state)
        {
            if (!CheckParams(g, month.TitleBounds))
            {
                return;
            }

            Color backStart, backEnd;
            LinearGradientMode?mode;

            if (state == MonthCalendarHeaderState.Default)
            {
                backStart = this.ColorTable.HeaderGradientBegin;
                backEnd   = this.ColorTable.HeaderGradientEnd;
                mode      = this.ColorTable.HeaderGradientMode;
            }
            else
            {
                backStart = this.ColorTable.HeaderActiveGradientBegin;
                backEnd   = this.ColorTable.HeaderActiveGradientEnd;
                mode      = this.ColorTable.HeaderActiveGradientMode;
            }

            this.FillBackgroundInternal(g, month.TitleBounds, backStart, backEnd, mode);
        }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MonthCalendarWeek"/> class.
 /// </summary>
 /// <param name="month">The corresponding <see cref="MonthCalendarMonth"/> that contains this instance.</param>
 /// <param name="weekNumber">The corresponding week number.</param>
 /// <param name="start">The start date of the week.</param>
 /// <param name="end">The end date of the week.</param>
 public MonthCalendarWeek(MonthCalendarMonth month, int weekNumber, DateTime start, DateTime end)
 {
    this.WeekNumber = weekNumber;
    this.Start = start;
    this.End = end;
    this.Month = month;
 }
Esempio n. 4
0
        /// <summary>
        /// Draws the background of the week header.
        /// </summary>
        /// <param name="g">The <see cref="Graphics"/> object used to draw.</param>
        /// <param name="month">The <see cref="MonthCalendarMonth"/> to draw the week header for.</param>
        public virtual void DrawWeekHeaderBackground(Graphics g, MonthCalendarMonth month)
        {
            if (!CheckParams(g, month.WeekBounds))
            {
                return;
            }

            FillBackground(
                g,
                month.WeekBounds,
                this.ColorTable.WeekHeaderGradientBegin,
                this.ColorTable.WeekHeaderGradientEnd,
                this.ColorTable.WeekHeaderGradientMode);
        }
Esempio n. 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MonthCalendarDay"/> class.
 /// </summary>
 /// <param name="month">The <see cref="MonthCalendarMonth"/> in which the day is in.</param>
 /// <param name="date">The <see cref="DateTime"/> the <see cref="MonthCalendarDay"/> represents.</param>
 public MonthCalendarDay(MonthCalendarMonth month, DateTime date)
 {
     this.Month         = month;
     this.Date          = date;
     this.MonthCalendar = month.MonthCalendar;
 }
Esempio n. 6
0
 /// <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 abstract void DrawMonthHeader(
     Graphics g,
     MonthCalendarMonth calMonth,
     MonthCalendarHeaderState state);
        /// <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);
            //         }
            //      }
            //   }
        }
 /// <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 abstract void DrawMonthHeader(
    Graphics g,
    MonthCalendarMonth calMonth,
    MonthCalendarHeaderState state);
      /// <summary>
      /// Draws the background of the week header.
      /// </summary>
      /// <param name="g">The <see cref="Graphics"/> object used to draw.</param>
      /// <param name="month">The <see cref="MonthCalendarMonth"/> to draw the week header for.</param>
      public virtual void DrawWeekHeaderBackground(Graphics g, MonthCalendarMonth month)
      {
         if (!CheckParams(g, month.WeekBounds))
         {
            return;
         }

         FillBackground(
            g,
            month.WeekBounds,
            this.ColorTable.WeekHeaderGradientBegin,
            this.ColorTable.WeekHeaderGradientEnd,
            this.ColorTable.WeekHeaderGradientMode);
      }
      /// <summary>
      /// Draws the title background for the specified <paramref name="month"/>.
      /// </summary>
      /// <param name="g">The <see cref="Graphics"/> object used to draw.</param>
      /// <param name="month">The <see cref="MonthCalendarMonth"/> to draw the title for.</param>
      /// <param name="state">The <see cref="MonthCalendarHeaderState"/> of the title.</param>
      public virtual void DrawTitleBackground(Graphics g, MonthCalendarMonth month, MonthCalendarHeaderState state)
      {
         if (!CheckParams(g, month.TitleBounds))
         {
            return;
         }

         Color backStart, backEnd;
         LinearGradientMode? mode;

         if (state == MonthCalendarHeaderState.Default)
         {
            backStart = this.ColorTable.HeaderGradientBegin;
            backEnd = this.ColorTable.HeaderGradientEnd;
            mode = this.ColorTable.HeaderGradientMode;
         }
         else
         {
            backStart = this.ColorTable.HeaderActiveGradientBegin;
            backEnd = this.ColorTable.HeaderActiveGradientEnd;
            mode = this.ColorTable.HeaderActiveGradientMode;
         }

         this.FillBackgroundInternal(g, month.TitleBounds, backStart, backEnd, mode);
      }
Esempio n. 11
0
      /// <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);
               }
            }
         }
      }
Esempio n. 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MonthCalendarDay"/> class.
 /// </summary>
 /// <param name="month">The <see cref="MonthCalendarMonth"/> in which the day is in.</param>
 /// <param name="date">The <see cref="DateTime"/> the <see cref="MonthCalendarDay"/> represents.</param>
 public MonthCalendarDay(MonthCalendarMonth month, DateTime date)
 {
    this.Month = month;
    this.Date = date;
    this.MonthCalendar = month.MonthCalendar;
 }