dotnet / dotnet/winforms

Font is not applied correctly if set on an invisible Control, and OnFontChanged is not called in PMv2 HDPI

Open
#10,237 6 comments 0 reactions 0 assignees View on GitHub
:boom: regression-release area-HDPI area-HDPI-PMv2 priority-1
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
1d 13m
Merged PRs (30d)
85

Description

### .NET version

.NET 8

### Did it work in .NET Framework?

Yes

### Did it work in any of the earlier releases of .NET Core or .NET 5+?

_No response_

### Issue description

In Per-Monitor v2 scenario if you set Font to an Invisible control and then set Visible to true, the Font size is scaled when the Handle of the control is created and no FontChanged event is generated in this case.
My scenario is 175% primary screen, 100% secondary screen.

![image](https://github.com/dotnet/winforms/assets/3384955/fa5e07b6-bd9a-45c7-bbf7-9f3ede92fd82)

### Steps to reproduce

Set up a primary screen to 175%, secondary to 100%
Run the attached DpiTest project on the secondary screen.
There are 2 labels, one of them is invisible, both are assigned the same font (size 12).
Clicking the Show button makes the second label visible.
I would expect the both buttons having the same font, or if this is a desired behavior (not sure why it actually should be), at least calling FontChanged, because the Font size is different than 12 which was assigned

![image](https://github.com/dotnet/winforms/assets/3384955/a5eb397b-2c67-4970-bc63-0d2821a74ac3)

[DpiTest.zip](https://github.com/dotnet/winforms/files/13277348/DpiTest.zip)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.