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?

拥有回忆 提交于 2019-12-10 08:01:07

问题


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"/>

where Width and Height are put to 86 because

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

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


回答1:


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();
    }
}

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.)



来源:https://stackoverflow.com/questions/12911553/how-can-i-get-the-real-size-of-the-lcd-display-diagonal-i-e-if-a-it-is-a-17

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!