I am developing a WinForms application in C#. It uses a panel to draw an image of the Mandelbrot fractal. In the manual for the program and whenever I post about it somewhere, I recommend people to set their scaling setting to 100%, as otherwise the images won't look nice. This is because on other settings, the image is scaled up after drawing it, and it becomes blurry. All other controls are blurry too.
For example: my panel is 500x500. The scaling in my Windows is set to 125%. When I run the program, the panel is internally still 500x500, but it appears as 625x625, blurry.
Instead, when the program is run, I want the panel to internally resize to 625x625, and appear as 625x625 too.
I have found the following solution: I found out about SetProcessDPIAware() (from here). Setting that makes the window not scale (it appears as if it was at the 100% scale setting), but the text does (and without becoming blurry). I can then, at the start of the program, calculate the appropriate multiplier (dpi = DpiX / 96) and give that to a huge method that includes commands like
xentrylabel.Location = new Point((int)(xentrylabel.Location.X * dpi),(int)(xentrylabel.Location.Y * dpi));
xentry.Location = new Point((int)(xentry.Location.X * dpi), (int)(xentry.Location.Y * dpi));
xentry.Size = new Size((int)(xentry.Width * dpi), (int)(xentry.Height * dpi));
One for every control property that might need to be updated. While writing this question, I got this idea and got started with it. However, I realised that this will need very many lines of code, so I wonder if there isn't a built-in way to do this. It seems like an option that many would like to go for, rather than their applications becoming blurry or hard to read on screens with high dpi.
Is this way of manually correcting positions and sizes the way to go, or is there a built-in way to scale the form for other DPI settings by actually scaling everything in the form, instead of scaling the end result?
Edit: From some comments it seems as if SetProcessDPIAware() alone should scale up everything. But in my experience, it doesn't. Here are some screenshots: Application on 100% scale setting: https://i.stack.imgur.com/pws9B.png
Application on 125% scale setting without SetProcessDPIAware(): https://i.stack.imgur.com/cE4Wx.png
Application on 125% scale setting with SetProcessDPIAware(): https://i.stack.imgur.com/oVA8W.png
I have now explicitly set the font for each control to ("Microsoft Sans Serif", 8). This also does not visibly change anything.
I don't know if I want to use 'app.manifest' or 'app.config' as I had never heard of either, interestingly. I would rather not manually recreate the behaviour if it is indeed built-in, as using a built-in method seems cleaner. – 607 Jan 01 '20 at 14:02
I do not use the designer. What properties are you talking about? Surely any properties that could be set in the designer can be set by code as well.
Why would I have to use Segoe UI? – 607 Jan 01 '20 at 14:20