// draws one day in the calendar grid private void DrawMonthCalendarDate (Graphics dc, Rectangle rectangle, MonthCalendar mc, DateTime date, DateTime month, int row, int col) { Color date_color = mc.ForeColor; Rectangle interior = new Rectangle (rectangle.X, rectangle.Y, Math.Max(rectangle.Width - 1, 0), Math.Max(rectangle.Height - 1, 0)); // find out if we are the lead of the first calendar or the trail of the last calendar if (date.Year != month.Year || date.Month != month.Month) { DateTime check_date = month.AddMonths (-1); // check if it's the month before if (check_date.Year == date.Year && check_date.Month == date.Month && row == 0 && col == 0) { date_color = mc.TrailingForeColor; } else { // check if it's the month after check_date = month.AddMonths (1); if (check_date.Year == date.Year && check_date.Month == date.Month && row == mc.CalendarDimensions.Height-1 && col == mc.CalendarDimensions.Width-1) { date_color = mc.TrailingForeColor; } else { return; } } } else { date_color = mc.ForeColor; } const int inflate = -1; if (date == mc.SelectionStart.Date && date == mc.SelectionEnd.Date) { // see if the date is in the start of selection date_color = mc.BackColor; // draw the left hand of the back ground Rectangle selection_rect = Rectangle.Inflate (rectangle, inflate, inflate); dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 0, 360); } else if (date == mc.SelectionStart.Date) { // see if the date is in the start of selection date_color = mc.BackColor; // draw the left hand of the back ground Rectangle selection_rect = Rectangle.Inflate (rectangle, inflate, inflate); dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 90, 180); // fill the other side as a straight rect if (date < mc.SelectionEnd.Date) { // use rectangle instead of rectangle to go all the way to edge of rect selection_rect.X = (int) Math.Floor((double)(rectangle.X + rectangle.Width / 2)); selection_rect.Width = Math.Max(rectangle.Right - selection_rect.X, 0); dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect); } } else if (date == mc.SelectionEnd.Date) { // see if it is the end of selection date_color = mc.BackColor; // draw the left hand of the back ground Rectangle selection_rect = Rectangle.Inflate (rectangle, inflate, inflate); dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 270, 180); // fill the other side as a straight rect if (date > mc.SelectionStart.Date) { selection_rect.X = rectangle.X; selection_rect.Width = rectangle.Width - (rectangle.Width / 2); dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect); } } else if (date > mc.SelectionStart.Date && date < mc.SelectionEnd.Date) { // now see if it's in the middle date_color = mc.BackColor; // draw the left hand of the back ground Rectangle selection_rect = Rectangle.Inflate (rectangle, 0, inflate); dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect); } // establish if it's a bolded font Font font = mc.IsBoldedDate (date) ? mc.bold_font : mc.Font; // just draw the date now dc.DrawString (date.Day.ToString(), font, ResPool.GetSolidBrush (date_color), rectangle, mc.centered_format); // today circle if needed if (mc.ShowTodayCircle && date == DateTime.Now.Date) { DrawTodayCircle (dc, interior); } // draw the selection grid if (mc.is_date_clicked && mc.clicked_date == date) { Pen pen = ResPool.GetDashPen (Color.Black, DashStyle.Dot); dc.DrawRectangle (pen, interior); } }