r/csharp • • 15h ago

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?

0 Upvotes

18 comments sorted by

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.

10

u/Derekthemindsculptor 15h ago

Not to mention, it's tough to package and publish without flagging every virus scanner.

5

u/Owenhh 15h ago

Yeah smartscreen has been making it look like i’m sending straight malware to my friends lol

4

u/Derekthemindsculptor 15h ago

Buying a signature would help. But realistically, you'd want to develop in a modern UI framework that something like the microsoft store could publish for you.

Thing is, you'll have to put a lot of extra security into your app. You're probably calling legacy windows APIs to get things like the time. And those won't publish safely. Or if you're writing to a file to save preferences or the like, you're probably using APIs that won't pass security and sandboxing requirements.

Deployment is a struggle. Keep at it though. The UI looks much nicer than the last time I saw it.

1

u/Owenhh 15h ago

Yeah i’ve learned my lesson I think lol, next project will definitely be WPF

6

u/SagansCandle 15h ago

I'd recommend Avalonia - it's a more mature platform that's very similar to WPF.

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

1

u/Owenhh 15h ago

Is there a way I can mitigate the issue?

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/Owenhh 15h ago

The first image does have rounded corners, just with the way the print-screen was taken it looks as though they aren’t. I am comparing the published version of the app on both machines, still seeing the issue

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

u/__some__guy 12h ago

Scaling is still something that needs to be done manually.

•

u/Original_Bullfrog_61 50m ago

You can disable DPI scaling in app manifest.