コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MonthCalendarMonth"/> class.
        /// </summary>
        /// <param name="monthCal">The <see cref="MonthCalendar"/> which hosts the <see cref="MonthCalendarMonth"/> instance.</param>
        /// <param name="date">The date that represents the month and year which is displayed in this instance.</param>
        public MonthCalendarMonth(MonthCalendar monthCal, DateTime date)
        {
            this.MonthCalendar = monthCal;
            this.Date          = date;
            this.location      = new Point(0, 0);

            MonthCalendarDate dt = new MonthCalendarDate(monthCal.CultureCalendar, date).FirstOfMonth.GetFirstDayInWeek(monthCal.FormatProvider);

            List <MonthCalendarDay>  dayList  = new List <MonthCalendarDay>();
            List <MonthCalendarWeek> weekList = new List <MonthCalendarWeek>();

            int dayAdjust = 0;

            while (dt.AddDays(dayAdjust).DayOfWeek != monthCal.FormatProvider.FirstDayOfWeek)
            {
                dayAdjust++;
            }

            int d = dayAdjust != 0 ? 8 - dayAdjust : 0;

            for (int i = dayAdjust; i < 42 + dayAdjust; i++, dt = dt.AddDays(1))
            {
                MonthCalendarDay day = new MonthCalendarDay(this, dt.Date);

                dayList.Add(day);

                if (day.Visible)
                {
                    if (this.firstVisibleDate == DateTime.MinValue)
                    {
                        this.firstVisibleDate = dt.Date;
                    }

                    if (!day.TrailingDate)
                    {
                        this.lastVisibleDate = dt.Date;
                    }
                }

                if (i == dayAdjust || ((i - d) % 7) == 0)
                {
                    DateTime weekEnd = dt.GetEndDateOfWeek(monthCal.FormatProvider).Date;

                    int weekNumEnd = DateMethods.GetWeekOfYear(monthCal.Culture, monthCal.CultureCalendar, weekEnd);

                    weekList.Add(new MonthCalendarWeek(this, weekNumEnd, dt.Date, weekEnd));
                }

                if (dt.Date == monthCal.CultureCalendar.MaxSupportedDateTime.Date)
                {
                    break;
                }
            }

            this.Days  = dayList.ToArray();
            this.Weeks = weekList.ToArray();
        }
コード例 #2
0
      /// <summary>
      /// Initializes a new instance of the <see cref="MonthCalendarMonth"/> class.
      /// </summary>
      /// <param name="monthCal">The <see cref="MonthCalendar"/> which hosts the <see cref="MonthCalendarMonth"/> instance.</param>
      /// <param name="date">The date that represents the month and year which is displayed in this instance.</param>
      public MonthCalendarMonth(MonthCalendar monthCal, DateTime date)
      {
         this.MonthCalendar = monthCal;
         this.Date = date;
         this.location = new Point(0, 0);

         MonthCalendarDate dt = new MonthCalendarDate(monthCal.CultureCalendar, date).FirstOfMonth.GetFirstDayInWeek(monthCal.FormatProvider);

         List<MonthCalendarDay> dayList = new List<MonthCalendarDay>();
         List<MonthCalendarWeek> weekList = new List<MonthCalendarWeek>();

         int dayAdjust = 0;

         while (dt.AddDays(dayAdjust).DayOfWeek != monthCal.FormatProvider.FirstDayOfWeek)
         {
            dayAdjust++;
         }

         int d = dayAdjust != 0 ? 8 - dayAdjust : 0;

         for (int i = dayAdjust; i < 42 + dayAdjust; i++, dt = dt.AddDays(1))
         {
            MonthCalendarDay day = new MonthCalendarDay(this, dt.Date);

            dayList.Add(day);

            if (day.Visible)
            {
               if (this.firstVisibleDate == DateTime.MinValue)
               {
                  this.firstVisibleDate = dt.Date;
               }

               if (!day.TrailingDate)
               {
                  this.lastVisibleDate = dt.Date;
               }
            }

            if (i == dayAdjust || ((i - d) % 7) == 0)
            {
               DateTime weekEnd = dt.GetEndDateOfWeek(monthCal.FormatProvider).Date;

               int weekNumEnd = DateMethods.GetWeekOfYear(monthCal.Culture, monthCal.CultureCalendar, weekEnd);

               weekList.Add(new MonthCalendarWeek(this, weekNumEnd, dt.Date, weekEnd));
            }

            if (dt.Date == monthCal.CultureCalendar.MaxSupportedDateTime.Date)
            {
               break;
            }
         }

         this.Days = dayList.ToArray();
         this.Weeks = weekList.ToArray();
      }
コード例 #3
0
 /// <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 abstract void DrawDay(Graphics g, MonthCalendarDay day);
コード例 #4
0
        /// <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);
            //   }
            //}
        }
コード例 #5
0
 /// <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 abstract void DrawDay(Graphics g, MonthCalendarDay day);
コード例 #6
0
      /// <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;

                  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 (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);
            }
         }
      }