Question

I have a C# .Net 4.0 Windows Forms app that is not scaling fonts correctly on Win7 and Win8.1 on a SUPER High Res display.

When run on a SUPER High Res tablet display ( 13.3" high-resolution QHD+ (3200 x 1800) display) and setting the scale factor to 200% in Windows Control Panel > Display, The DPI Virtualization scaling breaks.

The app loads up fine at first and everything looks great. Then when I click a button that creates a System.Windows.Media.MediaPlayer object, the DPI Virtualization scaling suddenly breaks.

Testing show it is that method that does it. System.Windows.Media.MediaPlayer mpPlayer = new MediaPlayer();

Tests show the same problem with MediaElement class.

And yes, this breaks even with a app manifest that has the DPI-Aware element.

So my question is... Is there a work around or fix for this? And what does MediaPlayer have to do with DPI Virtualization and DPI-Awareness? It doesn't have any visual methods or properties.

Update: MY FINAL SOLUTION THAT WORKS

After lots of research I'm posting the solution to save others the agony.

Add this assembly attribute to AssemblyInfo.cs

[assembly: System.Windows.Media.DisableDpiAwareness]

This attribute disables DPI awareness in the application assembly and allows DPI Virtualization to scale the app. MediaElement honors this attribute and does NOT change the app to DPI-aware.

If the app is Windows Forms (not WPF)... There is one extra step.

Add project References for these dlls or System.Windows.Media namespace will not be resolved.

PresentationCore.dll
WindowsBase.dll

Why Microsoft cannot include this assembly attribute in a Windows Forms dll is a mystery to me. But whateva.

Note: A developer reported in a forum that this assembly attribute is ignored when testing in Visual Studio Debug mode. You have to compile a Release version to test it.

Was it helpful?

Solution

Have you taken a look at Microsoft's Writing High-DPI Applications Guide? Additionally in this guide it's mentioned that you may need to call the SetProcessDpiAwareness API method. There's also a Word document linked in the Further Reading section that has some more relevant information that should get you started in the right direction.

Since 200% DPI scaling is new as of Windows 8.1, I'd expect there'd be some issues with older apps since this couldn't be tested (particularly in WinForms). Have you seen any issues on Windows 8.1 with lower scaling?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top