Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/System.Windows.Forms/System/Windows/Forms/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12626,6 +12626,7 @@ protected virtual void WndProc(ref Message m)
// s_defaultFont = Application.DefaultFont ?? SystemFonts.MessageBoxFont;
// So we need to check both variants - manually set font (Application.DefaultFont is not null) and auto system font

bool defaultFontChanged = false;
if (Application.DefaultFont is null) // auto system font
{
if (s_defaultFont is not null) // we need to check only if s_defaultFont already set
Expand All @@ -12634,6 +12635,7 @@ protected virtual void WndProc(ref Message m)
if (!s_defaultFont.Equals(font)) // the font has changed
{
s_defaultFont = font;
defaultFontChanged = true;
}
else
{
Expand All @@ -12643,8 +12645,25 @@ protected virtual void WndProc(ref Message m)
}
else // manually set font
{
Font? previousDefaultFont = s_defaultFont;
Application.ScaleDefaultFont(); // will update Application.s_defaultFont or Application.s_defaultFontScaled only if needed
s_defaultFont = Application.DefaultFont; // Application.s_defaultFontScaled ?? Application.s_defaultFont
defaultFontChanged = !s_defaultFont.Equals(previousDefaultFont);
}

// When the system default font changes and controls are using it, notify them so that
// AutoScaleMode.Font can immediately re-scale controls and update their sizes without
// requiring an application restart.
if (defaultFontChanged)
{
s_defaultFontHandleWrapper?.Dispose();
s_defaultFontHandleWrapper = null;
}

if (defaultFontChanged && !TryGetExplicitlySetFont(out _))
{
DisposeFontHandle();
OnFontChanged(EventArgs.Empty);
}
}
}
Expand Down
Loading