Bac Clunky
Bac Clunky

Reputation: 373

Change windows dpi setting C#

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!!!

Upvotes: 0

Views: 2914

Answers (2)

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.

Upvotes: 2

Dhaval Patel
Dhaval Patel

Reputation: 7591

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>

Upvotes: 0

Related Questions