Label.AutoSize bug
- Dominant language
- C#
- Stars
- 4.9k
- Forks
- 1.1k
- Avg merge
- 1d 13m
- Merged PRs (30d)
- 85
Description
### .NET version
.NET 7
### Did it work in .NET Framework?
Yes
### Did it work in any of the earlier releases of .NET Core or .NET 5+?
No
### Issue description
When you use property `Label.AutoSize = true`, calculating of Label size is wrong. It seems, .NET code uses default font instead of Label's font. If you set for Label big font, auto size of Label will be smaller then must be.
It can be connected with font scaling. I remember, in .NET Core 3 this feature had real displaying bugs. That was reason why I decided to stay with old good .NET Framework. It seems this font scaling still has bugs.
It is connected by some way with relationship between control and container. Let me explain. When Label is already in Form (is in the collection Form.Controls and is displayed) - AutoSize is OK, size is calculated correctly. But when Label exists yet separately (is not yet added to Form), AutoSize calculates wrong size. If I set bigger font for this separate Label, I see smaller auto size that it must be. It looks like ignoring of property Label.Font that I set.
### Steps to reproduce
1) Create windows form in VS constructor.
2) Create separate Label programmatically (not in constructor).
3) Set `Label.AutoSize = true`.
4) Set some text for Label.
5) Log size of Label.
6) Try to set another fonts for this Label (with different font sizes) and log size of Label.
7) Do all of that before adding Label to the form. Or even without adding at all.
--------------------------------------------------
With constructor, Label.AutoSize is OK. But when you need to create Label separately and know it's size - you get a bug with sizes.
Contributor guide
Assessment
This issue has not been assessed yet.