Skip to content

Conversation

@madewokherd
Copy link
Contributor

Pixel-accuracy is of dubious value. Programs that rely on this aren't likely to work outside of .NET Framework. Even .NET Core's winforms has diverged by changing its default font.

But, we do need to allocate enough space to draw the abbreviations for all the days of the week.

Surprisingly, this approach seems to match .NET Framework at the default size, judging by the hard-coded default.

For #58

Pixel-accuracy is of dubious value. Programs that rely on this
aren't likely to work outside of .NET Framework. Even .NET Core's
winforms has diverged by changing its default font.

But, we do need to allocate enough space to draw the abbreviations
for all the days of the week.

Surprisingly, this approach seems to match .NET Framework at the
default size, judging by the hard-coded default.

For DanielVanNoord#58
Copy link

@ris-work ris-work left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, I also had the same problem (with Eto.Forms, was not sure if it's an Eto issue)

@sancheolz
Copy link
Contributor

@madewokherd Your solution in my distribution does not display the calendar, without these changes it does. But in another version of the distribution, the opposite is true.

The following solution works for both versions of the distribution.

diff --git a/System.Windows.Forms/System.Windows.Forms/MonthCalendar.cs b/System.Windows.Forms/System.Windows.Forms/MonthCalendar.cs
index d38576e..4d80ae1 100644
--- a/System.Windows.Forms/System.Windows.Forms/MonthCalendar.cs
+++ b/System.Windows.Forms/System.Windows.Forms/MonthCalendar.cs
@@ -700,18 +700,30 @@ namespace System.Windows.Forms {
 			get {
 				if (this.Font == null) {
 					throw new InvalidOperationException();
 				}

 				// multiplier is sucked out from the font size
 				int multiplier = this.Font.Height;
 				// establis how many columns and rows we have
 				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);
 			}

@madewokherd
Copy link
Contributor Author

Oh. That makes sense.

Mind submitting your version?

@madewokherd madewokherd closed this Nov 7, 2025
@madewokherd madewokherd deleted the calendar branch November 7, 2025 21:05
@sancheolz
Copy link
Contributor

done #63

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants