/// <summary> /// The draw day. /// </summary> /// <param name="g"> /// The g. /// </param> /// <param name="day"> /// The day. /// </param> public override void DrawDay(Graphics g, MonthCalendarDay day) { if (!CheckParams(g, day.Bounds)) { return; } // if today, draw border if (day.Date == DateTime.Today) { this.DrawTodayLegend(g, day.Bounds); } // get the bounds of the day Rectangle rect = new Rectangle(day.Bounds.X + 2, day.Bounds.Y, day.Bounds.Width - 4, day.Bounds.Height); var boldDate = this._calendar.BoldedDatesCollection.Find(d => d.Value.Date == day.Date.Date); // if day is selected or in mouse over RequestState if (day.Selected) { g.FillRectangle(SelectedDayBackgroundBrush, rect); } else if (day.MouseOver) { g.FillRectangle(HoverDayBackgroundBrush, rect); } else if (!boldDate.IsEmpty && boldDate.Category.BackColorStart != Color.Empty && boldDate.Category.BackColorStart != Color.Transparent) { g.DrawRectangle(BorderPen, rect); } // get bolded dates List<DateTime> boldedDates = this._calendar.GetBoldedDates(); bool bold = boldedDates.Contains(day.Date) || !boldDate.IsEmpty; // draw the day using (StringFormat format = GetStringAlignment(this._calendar.DayTextAlignment)) { Color textColor = bold ? (boldDate.IsEmpty || boldDate.Category.ForeColor == Color.Empty || boldDate.Category.ForeColor == Color.Transparent ? InactiveTextColor : boldDate.Category.ForeColor) : (day.Selected ? SelectedDayTextColor : (day.MouseOver ? HoverDayTextColor : (day.TrailingDate ? TrailingDayColor : InactiveTextColor))); using (SolidBrush brush = new SolidBrush(textColor)) { using (Font font = new Font(this._calendar.Font.FontFamily, this._calendar.Font.SizeInPoints, FontStyle.Bold)) { // adjust width Rectangle textRect = day.Bounds; textRect.Width -= 2; // determine if to use bold font bool useBoldFont = day.Selected || bold; var calDate = new MonthCalendarDate(this._calendar.CultureCalendar, day.Date); string dayString = this._calendar.UseNativeDigits ? DateMethods.GetNativeNumberString( calDate.Day, this._calendar.Culture.NumberFormat.NativeDigits, false) : calDate.Day.ToString(this._calendar.Culture); if (this._calendar.Enabled) { g.DrawString(dayString, useBoldFont ? font : this._calendar.Font, brush, textRect, format); } else { ControlPaint.DrawStringDisabled( g, dayString, useBoldFont ? font : this._calendar.Font, Color.Transparent, textRect, format); } } } } }
/// <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);