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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
FroglegRank #1,020 · 1.9K reputationPosted Jun 14, 2011, 11:42 AM EDT
VulpesRank #55 · 29.2K reputationPosted Jun 15, 2011, 5:16 AM EDT
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.