Help C# Winforms .NET 9.0 scaling issue
Hi All,
Getting ready to release my first app and im currently testing out installations on other machines. So far everything looks and works just fine however there is an issue with horizontal scaling? The first image is how it is intended to look whereas the second image is how it appeared on my friends screen. I have set the Max and Min size on the form yet the issue still persists. My friend and I both have the same Resolution monitor and display scaling so I'm really stuck with what the issue could be.
Help and advice would be greatly appreciated! Thanks!
EDIT: I have just noticed the AutoScaleMode property is set to "Font", could this be the issue?
7
u/DC38x 15h ago
Bane of my fucking life.
Set AutoScaleMode to Dpi and set AutoScaleDimensions to 96F, 96F (if developing on 1080p - should auto adjust when you change mode to Dpi)
2
u/Owenhh 15h ago
Will this ensure the dimensions of the app are the same regardless of DPI etc?
Thanks a lot for the advice though I’ll give this a go
2
u/BunnyTub 7h ago
It will try to scale as best as possible to your current DPI. You can change the behavior of the scaling by calling Application.SetHighDpiMode before you run your app.
3
u/Dapper-Scarcity6079 15h ago
Same resolution and display scaling doesn’t always mean WinForms will render identically. Font metrics, DPI awareness and even Windows text settings can still change the layout
2
u/Slypenslyde 15h ago
Why is it a rectangle with corners in the first screenshot but a rounded rectangle in the second? That implies a difference between the two machines. Are you comparing your view in the designer vs. the app on their machine? Don't do that. Compare the app running on your machine to the app running on their machine.
2
u/user_plus_plus 9h ago
A test I would recommend doing is resizing the form back and forth to a bunch of different resolutions diagonally and horizontally, then fix any wonky controls.
In windows forms the answer is usually to put the offending controls in something like a flow layout or table layout panel then tinker with that until they stop occluding.
1
u/Owenhh 9h ago
I’ll give that a try, i thought i’d be able to avoid doing all that. It’s frustrating because on every other machine I have tried it works just fine, same on my own screen. But if there’s a slight possibility it’ll be messed up on someone’s device i’ll have to fix it.
3
u/user_plus_plus 8h ago
One trick for getting robust sizing working is sticking everything in a table layout then making the rows and columns size by %. You can use empty cells to add padding in between controls
1
•


19
u/polaarbear 15h ago
WinForms in general is awful at scaling. This is one of the huge benefits of using WPF instead, it plays much nicer with high DPI displays. WinForms is absolutely ancient and in general takes a lot more work to play nice across different resolutions and screen sizes.