System.Windows.Forms: Choose a size that fits what we'll draw.#59
Closed
madewokherd wants to merge 1 commit intoDanielVanNoord:masterfrom
Closed
System.Windows.Forms: Choose a size that fits what we'll draw.#59madewokherd wants to merge 1 commit intoDanielVanNoord:masterfrom
madewokherd wants to merge 1 commit intoDanielVanNoord:masterfrom
Conversation
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
ris-work
approved these changes
Sep 16, 2025
ris-work
left a comment
There was a problem hiding this comment.
Thanks for this, I also had the same problem (with Eto.Forms, was not sure if it's an Eto issue)
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);
}
|
Contributor
Author
|
Oh. That makes sense. Mind submitting your version? |
Contributor
|
done #63 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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