4

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

H.B.
  • 166,899
  • 29
  • 327
  • 400
Titianus
  • 53
  • 6

1 Answers1

5

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

Ekk
  • 5,627
  • 19
  • 27