4

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

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

其中 Width 和 Height 设置为 86,因为

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

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

4

1 回答 1

5

我在www.c-sharpcorner.com上发现了一个类似的问题。它提供了以下代码

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

于 2012-10-16T10:00:02.563 回答