dotnet / dotnet/winforms

AutoScaleMode = "Font" and increased text size in windows results in clipped texts

Open
#13,436 1 comment 0 reactions 1 assignee Claimed by @KlausLoeffelmann View on GitHub
area-HDPI
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
20h 23m
Merged PRs (30d)
103

Description

### .NET version

.NET 8.0

### Did it work in .NET Framework?

Not tested/verified

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

_No response_

### Issue description

Attached sample is a .NET8 application whose only form is set to `AutoScaleMode = AutoScaleMode.Font`. In the constructor of the form (before doing anything else), I set `this.Font = SystemFonts.MessageBoxFont;`" (which should be the same as `Application.SetDefaultFont(SystemFonts.MessageBoxFont);`).

Then I change the text size in windows. I have only a screenshot of the german version, but I hope you see which setting is meant (an english screenshot is found e.g. in #3583 - but this issue seems to target a different use case):
![Image](https://github.com/user-attachments/assets/2f076de4-5dec-4197-8dda-f75eabc6b8a1)
And I restart the app.

This results in clipped texts for some scalings, for others it seems to work better.

The method `Form.ScaleControl` is invoked if I change the text scale, and my sample prints the result (and the font size) in a textbox.

It seems the horizontal scaling factor is calculated in a way that might cause clipped texts. I would prefer a "larger than necessary scale factor", so that all texts are visible.

### Steps to reproduce

This is the sample: [AutoScaleModeFontTest.zip](https://github.com/user-attachments/files/20127220/AutoScaleModeFontTest.zip)

Change the scaling factor, then start the app.

This is the layout at default **"100%"**:

![Image](https://github.com/user-attachments/assets/9dc84958-c502-4db5-bb63-767103ca0760)

At **125%**, the label text is clipped, and the textbox content is not completely visible:

![Image](https://github.com/user-attachments/assets/05870910-b429-4b1b-95f9-47f90c777be0)

From here on, Github scales the screenshots again, so click them to see the original size!

At **150%**, the texts are completely shown, but the gap between the label text and the following textbox is smaller. Same for the textbox content and the right edge:

![Image](https://github.com/user-attachments/assets/fdd9a433-31c7-4ecb-8149-df0fd958c48d)

Same for **175%**:

![Image](https://github.com/user-attachments/assets/84b14a6a-d295-4e76-b6a7-1408af8a174f)

**200%** results in clipped texts again:

![Image](https://github.com/user-attachments/assets/0aef029d-47ca-4280-9f49-25d58fd84cf4)

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.