Search code examples
winformsvisual-studio-2015windows-10dpi

Winforms DPI scaling messed up with Windows 10 anniversary update and Visual Studio 2015 Update 4


I'm running my Winforms app using the Windows 10 anniversary update.

When running under the Visual Studio 2015 Update 4 debugger, the UI layout is completely messed up. Some controls are much smaller, others much larger, mouse hit detection is off, and so on.

When I run the exe by itself, without the debugger, it displays correctly.

Also, when running in the previous Windows 10 build 1511 and Visual Studio 2015 Update 3, the app displays fine as well.

So the problem is either with the anniversary build or with Visual Studio 2015 update 4. (I was unable to try the anniversary build with Visual Studio 2015 update 3 as the latter build is no longer available.)

What can account for this?

I've verified that the app.vshost.exe.config has the same content as the app.exe.config, and there are no DPI-aware properties in either.

Edit: I ran the app using "Start without debugging" and then attached the debugger. Attaching causes the UI to resize to a high-DPI unscaled view, i.e. everything is in native screen resolution - very small pixels across the entire UI. This is different from either of the two previous scenarios, and even more puzzling.

Edit 2 : After signing out and logging back in, the app displays fine. So at least there is a workaround. Obviously, the app cannot ship like this, so still looking for a way to avoid the problem in the first place.


Solution

  • Be sure to specify the DPI awareness level in your application manifest or via a call to SetProcessDpiAwareness.

    Are you loading any WPF content in your process?