Visual Studio (2015 and upcoming 2017) is a “DPI aware” application. Even our own WinForms based product Royal TS is a “DPI aware” application. But if you are a WinForms developer and use Visual Studio on a high DPI system, you will be surprised how Visual Studio messes up all your WinForms in the designer.
The problem is that Visual Studio is DPI aware but unlike Royal TS, for example, it seemingly cannot run with “display scaling” enabled (display scaling means, the process will be rendered/scaled as it would on a 96 DPI screen).
There are a couple of ways to enable/disable display scaling:
- The Compatibility tab in the .exe file properties dialog
- A .exe.manifest file with true|false
- A Win32 API call SetProcessDPIAware() when the process starts
My MVP fellow Carlos Quintero wrote a great blog post a while back with lots of references.
The main problem with Visual Studio is, the devenv.exe.manifest file is embedded in the executable and therefore the DPI awareness is enforced and cannot be overridden using the above methods.
It is possible to set DPI awareness for a specific application in the registry if you want to make Visual Studio System DPI “unaware”:
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\devenv.exe] "dpiAwareness"=dword:00000000
The above way is kind of “undocumented”. I did some research but couldn’t find any proper documentation about the dpiAwareness REG_DWORD in the Image File Execution Options key. Setting the REG_DWORD to 1 will make Visual Studio DPI aware again (requires a restart of Visual Studio).
Note: when Visual Studio is DPI “unaware” and display scaling is in effect, fonts and icons may look blurry but the WinForms designer will have no unwanted side-effects.
Attached you will find two .reg files which allows you to quickly switch display scaling on and off for Visual Studio (devenv.exe): Download devenv-dpi.zip
Thanks to Microsoft (Tanya) and to Carlos Quintero for helping me with this!