获取屏幕比例 [英] Get scale of screen

查看:64
本文介绍了获取屏幕比例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以获得分辨率,屏幕的内容是 Screen 类.因此,如果要在屏幕中央放置一些内容,则应使用 Screen.WorkingArea.Width Screen.WorkingArea.Height .

We can get resolution and stuff for our screen is Screen class. So, we should use Screen.WorkingArea.Width and Screen.WorkingArea.Height, if we want to place something in center of screen.

但是,在Windows 8.1(不确定其他操作系统)中,如果它们看起来太小,则可以缩放屏幕上的项目.您可以通过在桌面上调用上下文菜单来选择它,选择屏幕分辨率",然后选择使文本和其他项目变大或变小".

But, in Windows 8.1 (not sure about other OSs) there is possibility to scale items on screen, if they seem too small. You can check it, by calling context menu on desktop, select "Screen Resolution", and then select "Make text and other items larger or smaller".

问题是,它似乎确实提高了屏幕分辨率!因此, Screen.WorkingArea.Width Screen.WorkingArea.Height 将为您提供缩放值,并指向 Screen.WorkingArea.Width/2 Screen.WorkingArea.Height/2 将不再位于实际屏幕的中心(对于200%缩放,此点将位于屏幕的右下角).这可能会导致大量UI项的放置.

And the problem is, that, it seems, it does actually increase screen resolution! So, Screen.WorkingArea.Width and Screen.WorkingArea.Height will give you scaled value, and point Screen.WorkingArea.Width/2 Screen.WorkingArea.Height/2 will no longer in center of actual screen (for 200% scaling this point will be on lower right corner of screen). That might screw a lot of placement of UI items.

那么,是否有可能获得扩展的价值?我找不到任何包含此信息的课程.

So, is it possible to get value of scaling? I can't find any class containing this info.

推荐答案

大多数检索DPI的方法取决于现有控件,有时可能不方便.但是DPI始终可以从注册表中检索.在C#中:

Most methods to retrieve DPI depends on existing controls, which may be inconvenient sometimes. But DPI can be always retrieved from registry. In C#:

using Microsoft.Win32;
//...
var currentDPI = (int)Registry.GetValue("HKEY_CURRENT_USER\\Control Panel\\Desktop", "LogPixels", 96);

比例将为

var scale = 96/(float)currentDPI;

这篇关于获取屏幕比例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆