如何获得(lcd)显示器对角线的实际尺寸,即a是17英寸还是19英寸或其他尺寸? [英] How can I get the real size of the (lcd) display diagonal, i.e. if a it is a 17 inch or 19 inch or other?

查看:175
本文介绍了如何获得(lcd)显示器对角线的实际尺寸,即a是17英寸还是19英寸或其他尺寸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这对我很有用,因为我必须在屏幕上映射正确尺寸的对象。如果我使用的是分辨率为1280x1024且正常的96dpi设置的19英寸液晶显示器,则为了映射正确的1英寸正方形,我必须编写一个xaml,像这样

This is useful for me because I have to map objects with a correct dimension on screen; if I'm using a 19" lcd with 1280x1024 resolution and a normal 96dpi setting then in order to map a correct 1-inch square I have to write a xaml like this

<Rectangle Name="one_inch_side_on_19_inch_diag_display" Height="86" Width="86" Fill="Blue"/>

其中宽度和高度为86,因为

where Width and Height are put to 86 because

86〜= 96(每英寸点数) * 17(英寸)/ 19(英寸)

86 ~= 96 (dots-per-inch) * 17 (inches) / 19 (inches)

因为Windows假定17英寸显示器上的96dpi作为计算尺寸的基础...
谢谢

as windows assumes 96dpi on a 17" monitor as the base to calculate dimensions... Thanks

推荐答案

我发现类似的问题 www.c-sharpcorner .com 。它使用系统提供以下代码

I found a similar question on www.c-sharpcorner.com. It provides below code

using System;
using System.Management;

class Test
{
    static void Main()
    {
       var searcher = new ManagementObjectSearcher("\\root\\wmi","SELECT * FROM WmiMonitorBasicDisplayParams");

       foreach(ManagementObject mo in searcher.Get())
       {
           double width = (byte)mo["MaxHorizontalImageSize"] / 2.54; 
           double height = (byte)mo["MaxVerticalImageSize"] / 2.54; 
           double diagonal = Math.Sqrt(width * width + height * height);
           Console.WriteLine("Width {0:F2}, Height {1:F2} and Diagonal {2:F2} inches", width, height, diagonal);            
       }

       Console.ReadKey();
    }
}

我在具有2个监视器的本地计算机上对其进行了测试它返回几乎准确的结果。 (我的13英寸屏幕为12.70,24英寸屏幕屏幕为23.98。)

I tested it on my local machine which has 2 monitors and it return almost accurate result. (12.70 for my 13 inches and 23.98 for 24 inches screen.)

这篇关于如何获得(lcd)显示器对角线的实际尺寸,即a是17英寸还是19英寸或其他尺寸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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