From ade6762449fce1bc993800d27086e54080276fdc Mon Sep 17 00:00:00 2001 From: Alexander Khukhlaev Date: Mon, 10 Nov 2025 10:02:57 +0300 Subject: [PATCH 1/2] System.Windows.Forms: Choose a size that fits what we'll draw, close #58 We calculate the size of the calendar cell according to the selected font. --- .../System.Windows.Forms/MonthCalendar.cs | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/System.Windows.Forms/System.Windows.Forms/MonthCalendar.cs b/System.Windows.Forms/System.Windows.Forms/MonthCalendar.cs index 158e7d5..1a713a8 100644 --- a/System.Windows.Forms/System.Windows.Forms/MonthCalendar.cs +++ b/System.Windows.Forms/System.Windows.Forms/MonthCalendar.cs @@ -21,9 +21,6 @@ // // Authors: // John BouAntoun jba-mono@optusnet.com.au -// -// REMAINING TODO: -// - get the date_cell_size and title_size to be pixel perfect match of SWF using System; using System.Collections; @@ -711,8 +708,21 @@ public Size SingleMonthSize { int column_count = (ShowWeekNumbers) ? 8 : 7; int row_count = 7; // not including the today date - // set the date_cell_size and the title_size - date_cell_size = new Size ((int) Math.Ceiling (1.8 * multiplier), multiplier); + // Calculate date_cell_size + int maxWidth = 0; + int maxHeight = 0; + DateTime dt = new DateTime(0, DateTimeKind.Utc); + + for (int day = 0; day < 7; day++) + { + string dayStr = dt.AddDays(day).ToString("ddd"); + Size textSize = TextRenderer.MeasureText(dayStr, this.Font); + maxWidth = Math.Max(maxWidth, textSize.Width); + maxHeight = Math.Max(maxHeight, textSize.Height); + } + + date_cell_size = new Size(maxWidth + 2, maxHeight + 2); + title_size = new Size ((date_cell_size.Width * column_count), 2 * multiplier); return new Size (column_count * date_cell_size.Width, row_count * date_cell_size.Height + title_size.Height); From ec2065e31ab6ee6209d352960ba65363e5996eab Mon Sep 17 00:00:00 2001 From: Alexander Khukhlaev Date: Fri, 21 Nov 2025 11:44:38 +0300 Subject: [PATCH 2/2] 2 additional pixels have been removed to match the old behavior --- System.Windows.Forms/System.Windows.Forms/MonthCalendar.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/System.Windows.Forms/System.Windows.Forms/MonthCalendar.cs b/System.Windows.Forms/System.Windows.Forms/MonthCalendar.cs index 1a713a8..286a657 100644 --- a/System.Windows.Forms/System.Windows.Forms/MonthCalendar.cs +++ b/System.Windows.Forms/System.Windows.Forms/MonthCalendar.cs @@ -721,7 +721,7 @@ public Size SingleMonthSize { maxHeight = Math.Max(maxHeight, textSize.Height); } - date_cell_size = new Size(maxWidth + 2, maxHeight + 2); + date_cell_size = new Size(maxWidth, maxHeight); title_size = new Size ((date_cell_size.Width * column_count), 2 * multiplier);