Visual Studio WinForms Designer on HighDPI

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.

Solution

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!

3 thoughts on “Visual Studio WinForms Designer on HighDPI

  1. Hello, you saved my day! This trick will save me a lot of time, uselessly spent of switching between windows users with high and normal DPI. Thank you!

    Like

    1. Hi Edward,

      I haven’t tested it with Windows 8.1 so I can’t really tell. Unfortunately there’s no documentation (at least I couldn’t find any) about this flag. Since Windows 10 has a lot of changes and improvement around handling high DPI, there’s a good chance that this will only work on Windows 10.

      Regards,
      Stefan

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s