c# - How to configure an app to run correctly on a machine with a high DPI setting (e.g. 150%)? -


i've created simple winforms application in c#. when run application on machine high dpi settings (e.g. 150%), application gets scaled up. far good! instead of rendering fonts higher font size, texts scaled up, too. of course leads blurry text (on controls buttons etc.).

shouldn't windows take care of rendering texts correctly? example application's title bar rendered crisp & clear.

once go past 100% (or 125% "xp-style dpi scaling" checkbox ticked), windows default takes on scaling of ui. having app render output bitmap , drawing bitmap screen. rescaling of bitmap makes text inevitably fuzzy. feature called "dpi virtualization", keeps old programs usable on high resolution monitors.

you have explicitly let know can handle higher dpi settings adding <dpiaware> element manifest. msdn page is here isn't complete since omitting uac settings. project + add new item, pick "application manifest file". edit manifest text or copy/paste this:

<?xml version="1.0" encoding="utf-8"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestversion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" >     <assemblyidentity version="1.0.0.0" name="myapplication.app"/>     <trustinfo xmlns="urn:schemas-microsoft-com:asm.v2">         <security>             <requestedprivileges xmlns="urn:schemas-microsoft-com:asm.v3">                 <requestedexecutionlevel level="asinvoker" uiaccess="false" />             </requestedprivileges>         </security>     </trustinfo>     <asmv3:application>         <asmv3:windowssettings xmlns="http://schemas.microsoft.com/smi/2005/windowssettings">             <dpiaware>true</dpiaware>         </asmv3:windowssettings>     </asmv3:application> </assembly> 

you can pinvoke setprocessdpiaware() in main() method, necessary example if deploy clickonce:

    [stathread]     static void main() {         if (environment.osversion.version.major >= 6) setprocessdpiaware();         application.enablevisualstyles();         application.setcompatibletextrenderingdefault(false);         application.run(new form1());             // edit needed     }      [system.runtime.interopservices.dllimport("user32.dll")]     private static extern bool setprocessdpiaware(); 

update, common need bit easier if use vs2015 update 1 or higher. added manifest has relevant directive, remove comments.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -