Problems getting WinForms to scale correctly with DPI

我只是一个虾纸丫 提交于 2019-12-04 03:15:24
Anthony Huang

I had a similar problem just a few days ago. After a couple of hours research, I finally found a very simple solution -- adding <dpiAware> to the application manifest. Here is an example from Microsoft's website.

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" >
  <asmv3:application>
    <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
      <dpiAware>True</dpiAware>
    </asmv3:windowsSettings>
  </asmv3:application>
</assembly>

For my case, I need to set the <dpiAware> to Per-monitor to make it work normally. That is, change the line in the middle to <dpiAware>Per-monitor</dpiAware>.

The differences between each value are listed below(These are from MSDN):

  • False -- Sets the application to not DPI-aware.
  • True -- Sets the application to system DPI–aware.
  • Per-monitor -- On Windows 8.1, sets the application to per monitor-DPI aware. On Windows Vista through Windows 8, sets the application to not DPI–aware.
  • True/PM -- On Windows 8.1, sets the application to per monitor-DPI aware. On Windows Vista through Windows 8, sets the application to system-DPI aware.

Is it possible that with the monitor size and the higher DPI setting, that the screen is simply no longer big enough to display your entire form? I say that because I'm developing a 1024 x 768 winforms app, and playing around with user DPI settings. If I set the DPI to 150% I can no longer see the bottom portion of the form on my monitor, yet the app is scaling correctly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!