0

我设计了一个包含一些表格的项目。问题是它不能在宽显示器上正确显示。我已经搜索过它,发现它对于 dpi=96 可以正常工作。我想通过 vb.net 中的注册表更改 dpi(不是手动)这是我使用的代码:

    Dim dpi As Graphics = Me.CreateGraphics
    If (dpi.DpiX <> 96 And dpi.DpiY <> 96) Then
        Dim DPISetting As RegistryKey = My.Computer.Registry.CurrentUser.OpenSubKey("HKEY_CURRENT_USER\Control Panel\Desktop\WindowsMetrics", True)
        DPISetting.SetValue("AppliedDPI", 96) '**
    End If

但是我在 ** 行得到了一个 nullRefrence 异常。你调用的对象是空的。我真的研究了很长时间,但找不到问题所在。如果您对此有任何建议或解决方案,我将不胜感激。

4

1 回答 1

2

This design is fundamentally broken.

Your application should not change a global system setting just to work around a bug in the code. That's a good way to guarantee that your users will immediately uninstall your application and never use it again. If you're lucky, they won't tell their friends. You're usually not so lucky.

Instead of trying to make your hack work, why not just fix the actual problem? If your form doesn't display correctly at high (or low) DPI settings, you need to make it work in those scenarios. That's part of developing desktop apps—making sure that your app works in heterogeneous environments.

To that end, you might find the advice in these answers useful:

于 2012-05-26T08:48:38.440 回答