Handle DPI Awareness
Closed this issue · 11 comments
I have the following attribute specified in my project that utilizes WindowsFormsHost:
[assembly: System.Windows.Media.DisableDpiAwareness]
Which disables DpiAwareness and draws the screen as if it was unscaled (ex: 3840 × 2160 is drawn as if it was 1920 × 1080). I have this attribute applied because the screens are were designed prior to WinForms DPI Awareness features came about and the controls get all scrambled on screen without it.
However when I set FixAirspace=true the displayed image is 200% of the intended size. I assume that this is because while the drawn size is 1920 × 1080 the actual number of pixels to produce the image is 200% of that. Ergo, the image display is 200% of the intended size.
To reproduce you can set the Scaling factor in Display settings to something higher than 100% and watch it.
Just tried with that attribute removed and it produced the same effect on HiDPI displays.
Unfortunately, I don't have any high resolution monitors to test with and my laptop is only 1080p.
If I gave you a change, would you be able to test it out? It would just be a guess at this point.
I can test patches if need be, but you could also go to your Display Settings (Win10 Settings->System->Display) and raise the Scaling to something like 150% percent, that would mimic the effect. Your screen would be smaller for a bit but you can revert when you finished fixing it.
Great. That did it. I'll take a look and figure it out.
OK. I think it's fixed now. Did some quick testing and it looked good on this end. I just updated it from NuGet too so if that's how you got it before, you should get the update in the next couple of hours.
Works great now. 👍
Btw, this does not work for me on win10 4k resolution with 150% scaling.
The same has been reported on stackoverflow as a comment to the resolution which is in place here:
https://stackoverflow.com/a/21450169/648563 (See comment from @nerdtron)
So is there any known fix for this problem right now? I don't have a 4k display or laptop, so can't test it out myself.
I saw some comment on SO which suggested to combine the solution you are using here with the accepted answer from the same SO post.
I can give it a try tomorrow at work and report back here if it works.