public override void DrawMonthCalendar(Graphics dc, Rectangle clip_rectangle, MonthCalendar mc)
{
Rectangle client_rectangle = mc.ClientRectangle;
Size month_size = mc.SingleMonthSize;
// cache local copies of Marshal-by-ref internal members (gets around error CS0197)
Size calendar_spacing = (Size)((object)mc.calendar_spacing);
Size date_cell_size = (Size)((object)mc.date_cell_size);
// draw the singlecalendars
int x_offset = 1;
int y_offset = 1;
// adjust for the position of the specific month
for (int i=0; i < mc.CalendarDimensions.Height; i++)
{
if (i > 0)
{
y_offset += month_size.Height + calendar_spacing.Height;
}
// now adjust for x position
for (int j=0; j < mc.CalendarDimensions.Width; j++)
{
if (j > 0)
{
x_offset += month_size.Width + calendar_spacing.Width;
}
else
{
x_offset = 1;
}
Rectangle month_rect = new Rectangle (x_offset, y_offset, month_size.Width, month_size.Height);
if (month_rect.IntersectsWith (clip_rectangle)) {
DrawSingleMonth (
dc,
clip_rectangle,
month_rect,
mc,
i,
j);
}
}
}
Rectangle bottom_rect = new Rectangle (
client_rectangle.X,
Math.Max(client_rectangle.Bottom - date_cell_size.Height - 3, 0),
client_rectangle.Width,
date_cell_size.Height + 2);
// draw the today date if it's set
if (mc.ShowToday && bottom_rect.IntersectsWith (clip_rectangle))
{
dc.FillRectangle (GetControlBackBrush (mc.BackColor), bottom_rect);
if (mc.ShowToday) {
int today_offset = 5;
if (mc.ShowTodayCircle)
{
Rectangle today_circle_rect = new Rectangle (
client_rectangle.X + 5,
Math.Max(client_rectangle.Bottom - date_cell_size.Height - 2, 0),
date_cell_size.Width,
date_cell_size.Height);
DrawTodayCircle (dc, today_circle_rect);
today_offset += date_cell_size.Width + 5;
}
// draw today's date
StringFormat text_format = new StringFormat();
text_format.LineAlignment = StringAlignment.Center;
text_format.Alignment = StringAlignment.Near;
Rectangle today_rect = new Rectangle (
today_offset + client_rectangle.X,
Math.Max(client_rectangle.Bottom - date_cell_size.Height, 0),
Math.Max(client_rectangle.Width - today_offset, 0),
date_cell_size.Height);
dc.DrawString ("Today: " + DateTime.Now.ToShortDateString(), mc.bold_font, GetControlForeBrush (mc.ForeColor), today_rect, text_format);
text_format.Dispose ();
}
}
Brush border_brush;
if (mc.owner == null)
border_brush = GetControlBackBrush (mc.BackColor);
else
border_brush = SystemBrushes.ControlDarkDark;
// finally paint the borders of the calendars as required
for (int i = 0; i <= mc.CalendarDimensions.Width; i++) {
if (i == 0 && clip_rectangle.X == client_rectangle.X) {
dc.FillRectangle (border_brush, client_rectangle.X, client_rectangle.Y, 1, client_rectangle.Height);
} else if (i == mc.CalendarDimensions.Width && clip_rectangle.Right == client_rectangle.Right) {
dc.FillRectangle (border_brush, client_rectangle.Right - 1, client_rectangle.Y, 1, client_rectangle.Height);
} else {
Rectangle rect = new Rectangle (
client_rectangle.X + (month_size.Width*i) + (calendar_spacing.Width * (i-1)) + 1,
client_rectangle.Y,
calendar_spacing.Width,
client_rectangle.Height);
if (i < mc.CalendarDimensions.Width && i > 0 && clip_rectangle.IntersectsWith (rect)) {
dc.FillRectangle (border_brush, rect);
}
}
}
for (int i = 0; i <= mc.CalendarDimensions.Height; i++) {
if (i == 0 && clip_rectangle.Y == client_rectangle.Y) {
dc.FillRectangle (border_brush, client_rectangle.X, client_rectangle.Y, client_rectangle.Width, 1);
} else if (i == mc.CalendarDimensions.Height && clip_rectangle.Bottom == client_rectangle.Bottom) {
dc.FillRectangle (border_brush, client_rectangle.X, client_rectangle.Bottom - 1, client_rectangle.Width, 1);
} else {
Rectangle rect = new Rectangle (
client_rectangle.X,
client_rectangle.Y + (month_size.Height*i) + (calendar_spacing.Height*(i-1)) + 1,
client_rectangle.Width,
calendar_spacing.Height);
if (i < mc.CalendarDimensions.Height && i > 0 && clip_rectangle.IntersectsWith (rect)) {
dc.FillRectangle (border_brush, rect);
}
}
}
// draw the drop down border if need
if (mc.owner != null) {
Rectangle bounds = mc.ClientRectangle;
if (clip_rectangle.Contains (mc.Location)) {
// find out if top or left line to draw
if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.X, bounds.Bottom-1);
}
if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.Right-1, bounds.Y);
}
}
if (clip_rectangle.Contains (new Point(bounds.Right, bounds.Bottom))) {
// find out if bottom or right line to draw
if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1);
}
if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
dc.DrawLine (SystemPens.ControlText, bounds.Right-1, bounds.Y, bounds.Right-1, bounds.Bottom-1);
}
}
}
}