简体   繁体   English

更改Windows dpi设置C#

[英]Change windows dpi setting C#

I'm facing a issue which related to dpi setting of windows. 我面临与Windows的dpi设置有关的问题。 If the windows dpi setting is set to 100% everything is fine. 如果将Windows dpi设置设置为100%,则一切正常。 But if user changed it to 125%...some part of my application displayed a wrong size. 但是,如果用户将其更改为125%...我的应用程序的某些部分显示了错误的大小。 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% 我知道问题并且知道如何处理,但是我的客户希望在应用程序运行时,如果Windows的当前dpi设置不等于100%->将其更改为100%

And I'm standing still with the solution. 我站在解决方案上。 Do you have some solution to change windows dpi setting value? 您是否有解决方案来更改Windows dpi设置值?

Thanks in advanced!!! 提前致谢!!!

You can do this by modifying the registry value of the registry key HKEY_CURRENT_USER\\Control Panel\\Desktop:LogPixels . 您可以通过修改注册表项HKEY_CURRENT_USER\\Control Panel\\Desktop:LogPixels的注册表值来HKEY_CURRENT_USER\\Control Panel\\Desktop:LogPixels The type is REG_DWORD . 类型是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(0x60)对应于将DPI设置设置为“更小”(100%)。

  • 96 is "Smaller" (100%), 96是“ Smaller”(100%),
  • 120 is "Medium" (125%), 120是“中”(125%),
  • 144 is "Larger" (150%). 144是“更大”(150%)。

Note that the computer may still require a reboot or logout/login to make everything work as expected with that setting. 请注意,计算机仍可能需要重新启动或注销/登录才能使该设置按预期运行。

you have to use ViewBox in your applicaion. 您必须在应用程序中使用ViewBox。

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM