Change windows dpi setting C#

独自空忆成欢 提交于 2019-12-23 05:18:08

问题


I'm facing a issue which related to dpi setting of windows. If the windows dpi setting is set to 100% everything is fine. But if user changed it to 125%...some part of my application displayed a wrong size. I know the problem and I know how to deal with but my customer wants that when application running, if the current dpi setting of windows is not equal to 100% -> change it to 100%

And I'm standing still with the solution. Do you have some solution to change windows dpi setting value?

Thanks in advanced!!!


回答1:


You can do this by modifying the registry value of the registry key HKEY_CURRENT_USER\Control Panel\Desktop:LogPixels. The type is REG_DWORD.

You can see the Registry methods here to help how to modify the registry values.

Setting the value to 96 (0x60) corresponds setting the DPI settings to "Smaller" (100%).

  • 96 is "Smaller" (100%),
  • 120 is "Medium" (125%),
  • 144 is "Larger" (150%).

Note that the computer may still require a reboot or logout/login to make everything work as expected with that setting.




回答2:


you have to use ViewBox in your applicaion.

It does nothing more than scale to fit the content to the available size. It does not resize the content, but it transforms it. This means that also all text sizes and line widths were scaled. Its about the same behavior as if you set the Stretch property on an Image or Path to Uniform.

for eample

  <Viewbox Stretch="Uniform">
      <Button Content="Test" />
    </Viewbox>


来源:https://stackoverflow.com/questions/23886034/change-windows-dpi-setting-c-sharp

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