Hi
How to get the monitor size I mean its physical size how width and height and diagonal for example 17 inch or what
I don't need the resolution I tried
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Jun 15, 2011, 9:16 AM
I tried several different approaches but the only one which produced reasonably accurate results was the WmiMonitorBasicDisplayParams class (http://msdn.microsoft.com/en-us/library/aa394535(VS.85).aspx). This uses E_EDID and so is only supported on Vista or later versions of Windows.
The C# code is as follows:
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();
}
}
This gave a diagonal width of 15.33 ins on my Dell Laptop which actually has a diagonal of 15.6 ins. However, the properties in question are rounded to the nearer centimeter and so could therefore have an error of plus or minus 0.2 inches which is not too far away.
FroglegPosted Jun 14, 2011, 3:42 PM