简体   繁体   English

我如何从Visual Studio(c#)的显示设置中读取屏幕缩放比例(100%,125%,...)

[英]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.

相关问题 如何有效地读取我的 C# 服务的 Visual Studio 2019 memory 快照? - How do I read a Visual Studio 2019 memory snapshot of my C# service usefully? 如何在125%的Windows显示设置中使WPF Web浏览器应用程序缩放到屏幕大小? - How to make WPF web browser application scale to screen size in 125% windows display settings? 如何在Visual Studio C#上制作输出标签 - How do I make a Output Label on Visual Studio C# 如何在 Visual Studio 的 C# 中创建服务引用? - How do I create a Service Reference in C# in Visual Studio? 如何在 Visual Studio C# 中创建表单实例? - How do I create an instance of a form in Visual Studio C#? 如何在Visual Studio C中创建“项目概述”# - How do I create a “Project overview” in Visual Studio C# 如何在Visual Studio中安装C#类库? - How do I install a C# class library in Visual Studio? 如何在Visual Studio 2015中禁用C#6支持? - How do I disable C# 6 Support in Visual Studio 2015? 如何在Visual Studio 2010 C#中显示ApplicationRevision - How do I show the ApplicationRevision in Visual Studio 2010 C# 如何在 Mac 上的 Visual Studio 中编译 C# 应用程序? - How do I compile a C# application on a Mac in Visual Studio?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM