[英]How do i read the screen scaling factor (100%,125%,…) from display settings in Visual studio (c#)
I have looked at every similar question and none work for me. 我已经看过每个类似的问题,但没有一个对我有用。 I am programming a winForm that will show me the screen factor.
我正在编写一个winForm,它将向我显示屏幕因素。 I have tryed reading from Registry (doesnt work) i have tryed using DLL "gdi32.dll" , that works but only on Win10 not on Win7.
我尝试从注册表中读取(不工作),我尝试使用DLL“ gdi32.dll”起作用,但仅在Win10上有效,而在Win7上无效。 I Have also tryed :
我也尝试过:
float dpiX, dpiY;
using (Graphics graphics = Graphics.FromHwnd(IntPtr.Zero))
{
dpiX = graphics.DpiX;
dpiY = graphics.DpiY;
}
but it doesnt work also. 但它也不起作用。 I know that this question is repeated but all the answers that were in the previous questions didnt help, so thats why i am opening a new one.
我知道这个问题是重复的,但是先前问题中的所有答案都无济于事,所以这就是为什么我要打开一个新的。 So, can someone help me please?
那么,有人可以帮我吗?
You can use GetDpiForWindow with a Manifest. 您可以将GetDpiForWindow与清单一起使用。
uint nDPI = GetDpiForWindow(this.Handle);
I get => 我得到=>
100% : 96
125% : 120
150% : 144
175% : 168
Declaration => 声明=>
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern uint GetDpiForWindow(IntPtr hwnd);
Manifest => 清单=>
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.