我看过每一个类似的问题,但没有一个对我有效。我正在编写一个winForm,它将显示我的屏幕因素。我已经尝试从注册表读取(不工作)我已经尝试使用动态链接库"gdi32.dll“,但只在Win10上,而不是在Win7上。我也尝试过:
float dpiX, dpiY;
using (Graphics graphics = Graphics.FromHwnd(IntPtr.Zero))
{
dpiX = graphics.DpiX;
dpiY = graphics.DpiY;
}但它也不能工作。我知道这个问题是重复的,但之前问题中的所有答案都没有帮助,所以这就是为什么我要打开一个新的问题。有人能帮帮我吗?
发布于 2019-07-12 20:50:45
您可以将GetDpiForWindow与清单一起使用。
uint nDPI = GetDpiForWindow(this.Handle);我得到了=>
100% : 96
125% : 120
150% : 144
175% : 168声明=>
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern uint GetDpiForWindow(IntPtr hwnd);清单=>
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/PM</dpiAware>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitor</dpiAwareness>
</windowsSettings>
</application>https://stackoverflow.com/questions/57003193
复制相似问题